2016-11-11 67 views
0

我要把它放到我的代码:Python3:urllib.request里不工作

import urllib 

print(urllib.request("http://www.google.com")) 
input() 

我得到一个错误说:

Traceback (most recent call last): 
    File "C:\Users\David\Desktop\Interwebz.py", line 3, in <module> 
    print(urllib.request("http://www.google.com")) 
AttributeError: module 'urllib' has no attribute 'request' 

我不知道什么是错的。我检查了

C:/Users/David/AppData/Local/Programs/Python/Python35-32/Lib/urllib 

但我没有看到任何错误的文件。

请求似乎不存在于urllib中。 (尽管我在urllib文件夹中发现了一个request.py文件)

回答

1

你并没有真正说出你想要做什么,但我想你打开一个URL并阅读响应。

import urllib.request 

with urllib.request.urlopen("http://www.google.com") as f: 
    print(f.read())