2017-02-18 67 views
1

CODE:NameError:名称 '的urllib' 没有定义“

import networkx as net 
from urllib.request import urlopen 
def read_lj_friends(g, name): 
# fetch the friend-list from LiveJournal 
response=urllib.urlopen('http://www.livejournal.com/misc/fdata.bml?user='+name) 

错误:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
NameError: name 'urllib' is not defined 

回答

3

您已经导入urlopen直接,所以你应该是指它这样,而不是通过urllib

response = urlopen('...') 
0

尝试PLS:

from urllib.request import urlopen 

html = urlopen("http://www.google.com/") 
print(html.read) # Content 
+0

'urllib'是标准库的一部分。你不需要安装'urllib3'这是一个不同的库。另外,'urlopen'返回一个类似文件的对象,而不是html。 – interjay

+0

复杂,抱歉。我正在修复它。感谢您的警告。 –

相关问题