How to readlines() from urllib

后端 未结 2 1066
北恋
北恋 2021-01-07 11:31

I have program using http and I want to read data from http:

data = urllib.request.urlopen(someAddress).read()

And prepare from it list of

2条回答
  •  暖寄归人
    2021-01-07 12:17

    I usually do something like. I use urllib2, but it shouldn't be so different:

    from urllib2 import Request, urlopen
    
    def getPage(link, splitting = '\n'):
        request = Request(link)
        try:
            response = urlopen(request)
        except IOError:
            return -1
        else:
            the_page = response.read()
            return the_page.split(splitting)
    

提交回复
热议问题