NameError: name 'urllib' is not defined "

2020-06-17 07:24发布

CODE:

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)

ERROR:

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

4条回答
ら.Afraid
2楼-- · 2020-06-17 07:42

You can also try in Python 3:

from six.moves import urllib

temp_file, _ = urllib.request.urlretrieve(url)
查看更多
迷人小祖宗
3楼-- · 2020-06-17 07:50

Try pls:

from urllib.request import urlopen

html = urlopen("http://www.google.com/")
print(html.read) # Content 
查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-06-17 07:52

You've imported urlopen directly, so you should refer to it like that rather than via urllib:

response = urlopen('...')
查看更多
该账号已被封号
5楼-- · 2020-06-17 07:52

For your case:

import networkx as net
from urllib.request import urlopen
def read_lj_friends(g, name):
# fetch the friend-list from LiveJournal
response=urlopen('http://www.livejournal.com/misc/fdata.bml?user='+name)
查看更多
登录 后发表回答