Jan-29-2019, 01:52 PM
Error: module 'urllib' has no attribute 'urlopen'
What is it then?
(beginner)
What is it then?
(beginner)
Error: module 'urllib' has no attribute 'urlopen'
|
Jan-29-2019, 01:52 PM
Error: module 'urllib' has no attribute 'urlopen'
What is it then? (beginner)
There is batteries-included urllib.request described as 'Extensible library for opening URLs' in Python documentation.
If you do: import urllib.request then you can access urlopen like this: urllib.request.urlopen() Alternatively just urlopen (if using from urllib.request import urlopen )
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
The import has changed in Python 3.
>>> import urllib.request >>> >>> req = urllib.request.urlopen('https://www.python.org/')But i would advice to not use urllib at all,use Requests . >>> import requests >>> >>> req = requests.get('https://www.python.org/') >>> req.status_code 200 >>> req.encoding 'utf-8'A typically example to load a site and do web-scraping. from bs4 import BeautifulSoup import requests url = 'https://www.python.org/' url_get = requests.get(url) soup = BeautifulSoup(url_get.content, 'lxml') print(soup.select('head > title')[0].text)
|
|