Python Forum
Error: module 'urllib' has no attribute 'urlopen'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: module 'urllib' has no attribute 'urlopen'
#1
Error: module 'urllib' has no attribute 'urlopen'


What is it then?

(beginner)
Reply
#2
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.
Reply
#3
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)
Output:
Welcome to Python.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting from <td> tag by using urllib,Beautifulsoup KuroBuster 2 2,027 Aug-20-2021, 07:53 AM
Last Post: KuroBuster
  Can urlopen be blocked by websites? peterjv26 2 3,324 Jul-26-2020, 06:45 PM
Last Post: peterjv26
  Beginner: urllib error tomfry 7 6,473 May-03-2020, 04:35 AM
Last Post: Larz60+
  urllib.error.HTTPError: HTTP Error 404: Not Found ckkkkk 4 8,638 Mar-03-2020, 11:30 AM
Last Post: snippsat
  Error object has no attribute text hcyeap 3 13,843 May-21-2019, 07:12 AM
Last Post: buran
  SSLCertVerificationError using urllib (urlopen) FalseFact 1 5,837 Mar-31-2019, 08:34 AM
Last Post: snippsat
  [Errno11004] Get addrinfo failed with urlopen prashanth0988 2 13,749 Aug-02-2018, 01:41 PM
Last Post: iiooii
  urllib request urlopen? nutgut 4 5,440 Apr-14-2018, 01:12 PM
Last Post: nutgut
  urllib urlopen getting error 400 on 1 specific page glidecode 4 4,067 Mar-01-2018, 11:01 PM
Last Post: glidecode
  AttributeError: 'NoneType' object has no attribute error vk7 1 6,831 Feb-02-2018, 08:36 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020