-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-1.py
41 lines (32 loc) · 951 Bytes
/
http-1.py
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
import urllib.request
import json
import urllib.parse
def searchMovie():
title = "dangal"
url = "http://www.omdbapi.com/?t=%s" % urllib.parse.quote(title)
try:
conn = urllib.request.urlopen(url)
except:
print("Failure in connecting to IMDB")
return
print("Headers: ")
for k, v in conn.getheaders():
print(k, v)
print(" ")
jdata = conn.read()
try:
str_data = jdata.decode('utf8')
print("str_data: ", str_data)
print(" ")
js_data2 = json.dumps(str_data, sort_keys=True, indent=2)
print("js_data2: ", js_data2)
print(" ")
js_data = json.loads(str_data)
print("Title: ", js_data['Title'])
print("Year: ", js_data['Year'])
print("Plot: ", js_data['Plot'])
print("Actors: ", js_data['Actors'])
except:
print("Sorry, no data found for movie")
return
searchMovie()