forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie_details
53 lines (41 loc) · 1.33 KB
/
movie_details
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import mechanize
from bs4 import BeautifulSoup
import urllib2
# Create a Browser
b = mechanize.Browser()
# Disable loading robots.txt
b.set_handle_robots(False)
b.addheaders = [('User-agent',
'Mozilla/4.0 (compatible; MSIE 5.0; Windows 98;)')]
nm=raw_input("enter title ")
# Navigate
b.open('http://www.imdb.com/search/title')
# Choose a form
b.select_form(nr=1)
b['title'] = nm
b.find_control(type="checkbox",nr=0).get("feature").selected = True
# Submit
fd = b.submit()
soup = BeautifulSoup(fd.read(),'html5lib')
#data= soup.find_all('td',class_="title")
#for div in data:
# links= div.find_all('a')
# for a in links:
# print a['href'];
for div in soup.findAll('td', {'class': 'title'},limit=1):
a = div.findAll('a')[0]
print a.text.strip(), '=>', a.attrs['href']
hht='http://www.imdb.com'+a.attrs['href']
print(hht)
page=urllib2.urlopen(hht)
soup2 = BeautifulSoup(page.read(),'html.parser')
print("title of the movie: ")
print(soup2.find(itemprop="name").get_text())
print("timerun: ")
print(soup2.find(itemprop="duration").get_text())
print("genre: ")
print(soup2.find(itemprop="genre").get_text())
print("current IMDB rating:")
print(soup2.find(itemprop="ratingValue").get_text())
print("summary:")
print(soup2.find(itemprop="description").get_text())