| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
一直报错,说:AttributeError: module 'urllib' has no attribute 'request' 
这是为什么?哪里错了? 
- import urllib
 
 - def askURL(url):
 
 -     head={
 
 -         'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33'
 
 -     }
 
 - request = urllib.request.Request(url, headers=head)
 
 - html = ''
 
 - try:
 
 -     response = urllib.request.urlopen(request)
 
 -     html = response.read().decode('utf-8')
 
 -     print(html)
 
 - except urllib.error.URLError as e:
 
 -     print(e.reason)
 
  
 
- askURL('https://movie.douban.com/top250?start=0')
 
  复制代码 
 本帖最后由 临时号 于 2022-6-9 21:43 编辑 
- import urllib.request
 
 - import urllib.error
 
 - def askURL(url):
 
 -         head={
 
 -          'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.33'
 
 -         }
 
 -         request = urllib.request.Request(url, headers=head)
 
 -         html = ''
 
 -         try:
 
 -                 response = urllib.request.urlopen(request)
 
 -                 html = response.read().decode('utf-8')
 
 -                 print(html)
 
 -         except urllib.error.URLError as e:
 
 -                 print(e.reason)
 
  
 
- askURL('https://movie.douban.com/top250?start=0')
 
  复制代码 
 
 
 |   
 
 
 
 |