这是我的代码:
import urllib2.request
response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)
有什么帮助吗?
如中所述urllib2文档 https://docs.python.org/2/library/urllib2.html:
The urllib2
模块已被拆分为 Python 3 中的多个模块,名为urllib.request
and urllib.error
. The 2to3
将源代码转换为 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/")
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)