Skip to content

Commit 3562d1b

Browse files
Update imdb.py
Added comments to explain the code!
1 parent c02026d commit 3562d1b

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Automation/src/imdb_scraper/imdb.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
1-
import requests
1+
import requests #for imdb movie requests.
22

33
from bs4
4-
import BeautifulSoup
4+
import BeautifulSoup #Beautifulsoup for desktop notif.
55

66
print('Enter movie/Tv series name')
77

88
movie = input()
99

1010
print()
1111

12-
url = 'http://www.imdb.com/find?ref_=nv_sr_fn&q=' + movie + '&s=all'
12+
url = 'http://www.imdb.com/find?ref_=nv_sr_fn&q=' + movie + '&s=all' #imdb's search API.
1313

14-
def get_title(movie_url):
14+
def get_title(movie_url):
1515

16-
source_code = requests.get(movie_url)
16+
source_code = requests.get(movie_url) #getting movie imdb page url from user input.
1717

18-
plain_text = source_code.text
18+
plain_text = source_code.text #convert to plain text
1919

2020
soup = BeautifulSoup(plain_text, 'lxml')
2121

2222
for title in soup.findAll('div', {
2323
'class': 'title_wrapper'
2424
}):
2525

26-
return title.find('h1').text.rstrip()
27-
26+
return title.find('h1').text.rstrip()
2827
source_code = requests.get(url)
2928

3029
plain_text = source_code.text
@@ -35,15 +34,15 @@ def get_title(movie_url):
3534
'class': 'result_text'
3635
}):
3736

38-
href = td.find('a')['href']
37+
href = td.find('a')['href'] #find movie page in imdb
3938

40-
movie_page = 'http://www.imdb.com' + href
39+
movie_page = 'http://www.imdb.com' + href
4140

4241
break
4342

4443
movie_name = get_title(movie_page)
4544

46-
def get_movie_data(movie_url):
45+
def get_movie_data(movie_url): #getting movie data like reviews and genre.
4746

4847
source_code = requests.get(movie_url)
4948

@@ -55,7 +54,7 @@ def get_movie_data(movie_url):
5554
'class': 'ratingValue'
5655
}):
5756

58-
print('Imdb rating of the movie/Tv Series "' + movie_name + '" is: ', end = '')
57+
print('Imdb rating of the movie/Tv Series "' + movie_name + '" is: ', end = '') #showing movie rating as a desktop notification
5958

6059
print(div.text)
6160

@@ -65,7 +64,7 @@ def get_movie_data(movie_url):
6564
'class': 'summary_text'
6665
}):
6766

68-
print('Summary of the movie/Tv series:')
67+
print('Summary of the movie/Tv series:') #showing summary of movie as desktop notif.
6968

7069
print(div.text.lstrip())
7170

@@ -81,7 +80,7 @@ class ':'
8180

8281
for genre in print_genre.findAll('a'):
8382

84-
print(genre.text, end = ' |')
83+
print(genre.text, end = ' |') #showing genre.
8584

8685
print()
8786
''

0 commit comments

Comments
 (0)