Python urllib 模块错误!AttributeError: 'module' 对象没有属性 'request'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19729927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
urllib module error! AttributeError: 'module' object has no attribute 'request'
提问by Manas Chaturvedi
I was currently playing with the 'urllib' module in python, and tried this to extract source code of a website:
我目前正在使用 python 中的 'urllib' 模块,并尝试使用它来提取网站的源代码:
import urllib
temp = urllib.request.urlopen('https://www.quora.com/#')
However, I get the following error:
但是,我收到以下错误:
Traceback (most recent call last): File "", line 1, in temp = urllib.request.urlopen('https://www.quora.com/#') AttributeError: 'module' object has no attribute 'request'
回溯(最近一次调用):文件“”,第 1 行,在 temp = urllib.request.urlopen(' https://www.quora.com/#') AttributeError: 'module' object has no attribute 'request'
I am using Python 2.7.5 by the way.
顺便说一下,我正在使用 Python 2.7.5。
采纳答案by falsetru
It seems like you are reading Python 3.x documentation.
您似乎正在阅读Python 3.x 文档。
It's urllib.urlopenin Python 2.x.
它urllib.urlopen在 Python 2.x 中。

