繁体   English   中英

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

[英]in my python 3 i cannot use urllib.request as it says i don't have this submodule so how can i access websites data?

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

go 通过文档并使用它重新安装 urllib 然后尝试,或者您可以尝试使用此脚本

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

一般来说,建议使用最新的 python http 客户端 - urllib3 或 requests

pip3 install urllib3

pip3 install requests

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

import requests

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM