Python 3.2问题
我正在使用Python 3.2。我可以像 2.x 版本一样导入“urllib”库。但我找不到 urlopen、urlretrieve 等方法。这是怎么回事?如何在 v3.2 上检索网页?
我尝试导入 urllib2 和 urllib3 库。但我的机器说它找不到这些模块,因此无法导入。为什么 v3.2 不支持这两个最新的库?
I am using Python 3.2. I can import "urllib" library just like with 2.x version. But I can't find methods such as urlopen, urlretrieve, etc. What gives? How do I retrieve a webpage on v3.2?
I have tried to import urllib2 and urllib3 libraries. But my machine says it can't find those modules so not importable. Why these two newest libraries aren't supported in v3.2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用
urllib.request
。示例此处。You should use
urllib.request
. Example here.2.x 文档提到,在 Python 3.x 中,模块已分为
urllib.request
和urllib.error
。如果您有一些 Python 2.x 代码并希望将模块转换为 3.x,您可以使用2to3
工具。The 2.x docs mention that in Python 3.x, the modules have been split into
urllib.request
andurllib.error
. If you have some Python 2.x code and want to convert the modules to 3.x, you may be able to use the2to3
tool.它在新版本中发生了变化,现在被拆分为 urllib.request。
您要查找的很多内容都在 urllib.request 的 python 库部分中 有人刚刚提到了一个实际的示例显示如何使用 urllib.request.urlopen 的文档。
It was changed in the newer versions and was split up to now be
urllib.request
.A lot of what you're looking for is in the python library section on urllib.request and someone just mentioned an actual example from the documents that shows how the urllib.request.urlopen can be used.
Python 3000 代表着与过去的决裂。函数已被清理,语法已被修改,并且标准库已被重新组织以提供更逻辑的任务和能力分组。
TL;DR:事情发生了变化。
Python 3000 represents a break with the past. Functions have been cleaned up, syntax has been modified, and the stdlib has been reorganized to provide a more logical grouping of tasks and abilities.
TL;DR: Things change.