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 lines like returning lines by readlines() method for file.
How to do it?
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 lines like returning lines by readlines() method for file.
How to do it?
urlopen()
returns an object that acts just like a file, and supports.readlines()
:It also supports iteration:
You already called
.read()
on the response object; you could also just callstr.splitlines()
on that:where
True
tellsstr.splitlines()
to preserve line endings.I usually do something like. I use urllib2, but it shouldn't be so different: