gpt4 book ai didi

python - 导入错误 : No module name urllib2

转载 作者:IT老高 更新时间:2023-10-28 12:03:54 24 4
gpt4 key购买 nike

这是我的代码:

import urllib2.request

response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)

有什么帮助吗?

最佳答案

urllib2 documentation 中所述:

The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

所以你应该说

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

您当前编辑的代码示例不正确,因为您说的是 urllib.urlopen("http://www.google.com/") 而不仅仅是 urlopen("http://www.google.com/")

关于python - 导入错误 : No module name urllib2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2792650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com