import urllib.request
with urllib.request.urlopen('https://pakstockexchange.com/stock2/index_new.php?section=research&page=show_price_table_new&symbol=ABOT') as response:
html=respnse.read()
import pandas as pd
df=pd.read_html('https://pakstockexchange.com/stock2/index_new.php?section=research&page=show_price_table_new&symbol=ABOT')
print(df)我使用了两个不同的代码从一个网站获取数据表,其中的数据是免费的。但每次我运行我的程序时,我都会得到以下错误'urllib.error.HTTPError: HTTP error403:禁止‘。此外,这些链接在浏览器中似乎工作得很好。你知道怎么解决这个问题吗?
PS:无需身份验证即可查看数据。
发布于 2017-02-04 00:24:12
我不确定为什么服务器会准确地抛出301,但通常不鼓励直接使用urllib来处理这样的高级别请求。您应该改用requests包。
等效的requests fetch:
r = requests.get("https://pakstockexchange.com/stock2/index_new.php?section=research&page=show_price_table_new&symbol=ABOT")工作正常。
r.status_code == 200
Truehttps://stackoverflow.com/questions/42027047
复制相似问题