小编Him*_*ddy的帖子

AttributeError:模块'urllib'没有属性'urlopen'

我刚开始学习Python.我确信我写的代码是正确的.

import urllib
import re


stockname = input('Enter the stock name : ')

url = "https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol="+stockname+"&illiquid=0&smeFlag=0&itpFlag=0"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<span id="lastPrice">'+stockname+'</span>'
pattern = re.compile(regex)
price = re.findall(pattern,htmltext)
print (price)
Run Code Online (Sandbox Code Playgroud)

但无论我尝试多少,我都会继续犯这个错误.

Enter the stock name : tcs
Traceback (most recent call last):
  File "C:\Users\.....\Desktop\stockq.py", line 8, in <module>
    htmlfile = urllib.urlopen(url)
AttributeError: module 'urllib' has no attribute 'urlopen'
Run Code Online (Sandbox Code Playgroud)

我也试过`urllib.request.我收到这个错误.

Traceback (most recent call last):
  File "C:\Users\HiMMi\Desktop\stockq.py", line 8, in <module>
    htmlfile = urllib.request.urlopen(url)
  File "C:\Users\HiMMi\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line …
Run Code Online (Sandbox Code Playgroud)

python web-scraping

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×1

web-scraping ×1