2017-02-18 66 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

複雜,抱歉。我正在修復它。感謝您的警告。 –

相關問題