在我的python 3中,我无法使用urllib.request,因为它说我没有此子模块,所以我如何访问网站数据?

问题描述 投票:1回答:2

我使用python3,并且urllib模块具有解析,错误,robotparse,只有它不会像import urllib.request和urllib.request.urlopen这样的命令,所以替代品或如何修复它

python python-3.x web urllib python-webbrowser
2个回答
0
投票

仔细阅读文档并使用它重新安装urllib,然后尝试或可以尝试使用此脚本

 from urllib.request import urlopen
 html = urlopen("http://www.google.com/").read()
 print(html)

0
投票

通常,建议使用最新的python http客户端-urllib3或请求

pip3 install urllib3

pip3 install requests

[如果您尝试使用其URL阅读网站内容,则可以通过请求来完成:

import requests

response = requests.get("https://stackoverflow.com/")
print(response.text)

© www.soinside.com 2019 - 2024. All rights reserved.