我试图使用Python下载一个网站的HTML源代码,但是我收到了这个错误。
Traceback (most recent call last):
File "C:\Users\Sergio.Tapia\Documents\NetBeansProjects\DICParser\src\WebDownload.py", line 3, in <module>
file = urllib.urlopen("http://www.python.org")
AttributeError: 'module' object has no attribute 'urlopen'
我在这里遵循指南:http://www.boddie.org.uk/python/HTML.html
import urllib
file = urllib.urlopen("http://www.python.org")
s = file.read()
f.close()
#I'm guessing this would output the html source code?
print(s)
我在用Python 3。
在PythonV3中,“urllib.request”本身就是一个模块,因此这里不能使用“urllib”。
与Python2+3兼容的解决方案是:
这在Python2.x中有效
对于Python 3,请查看docs:
相关问题 更多 >
编程相关推荐