python 3.x - urlopen is not working for python3 -


i trying fetch data url. have tried following in python 2.7:

import urllib2 ul response = ul.urlopen("http://in.bookmyshow.com/") page_content = response.read() print page_content 

this working fine. when try in python 3.4 throwing error:

file "c:\python34\lib\urllib\request.py", line 161, in urlopen     return opener.open(url, data, timeout) 

i using:

import urllib.request response = urllib.request.urlopen('http://in.bookmyshow.com/') data = response.read() print data 

it works me (python 3.4.3). need use print(data) in python 3.

as side note may want consider requests makes way easier interact via http(s).

>>> import requests >>> r = requests.get('http://in.bookmyshow.com/') >>> r.ok true >>> plaintext = r.text 

finally, if want data such complicated pages (which intended displayed, opposed api), should have @ scrapy make life easier well.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -