NameError: name 'urllib' is not defined "

后端 未结 5 1711
不思量自难忘°
不思量自难忘° 2021-02-09 07:47

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(\'         


        
相关标签:
5条回答
  • 2021-02-09 08:23

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

    response = urlopen('...')
    
    0 讨论(0)
  • 2021-02-09 08:30

    Try pls:

    from urllib.request import urlopen
    
    html = urlopen("http://www.google.com/")
    print(html.read) # Content 
    
    0 讨论(0)
  • 2021-02-09 08:30

    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)
    
    0 讨论(0)
  • 2021-02-09 08:35

    You can also try in Python 3:

    from six.moves import urllib
    
    temp_file, _ = urllib.request.urlretrieve(url)
    
    0 讨论(0)
  • 2021-02-09 08:47

    Just put import urllib at the top of your code

    0 讨论(0)
提交回复
热议问题