NameError: name 'urllib' is not defined "

后端 未结 5 1572
日久生厌
日久生厌 2021-02-09 08:13

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

    Just put import urllib at the top of your code

    0 讨论(0)
  • 2021-02-09 08:26

    You can also try in Python 3:

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

    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:39

    Try pls:

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

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

    response = urlopen('...')
    
    0 讨论(0)
提交回复
热议问题