I asked a similar question yesterday but I included some code that basically took my question on a different tangent than I had intended. So I shall try again.
I am rewriting a python script that crawls a website to find a few hundred text files, I have no interest in any content of the text file beyond the second line of the file. Previously I would download all of the files then loop through them all to extract the second line. I would now like to open each file as my script discovers it, grab the second line, and close it without downloading to my harddrive then opening it.
So basically is there a way I can open a file that is at http://www.example.com/123456.txt and take the second line from that file copy it to an array or something without downloading it and then opening it.
Well, you could use
urllib2.urlopen()to just get the file contents into memory, extract the second line, and then immediately discard the file from memory, if you wanted, without ever hitting your disk.You are going to have to download the contents over the internet, though.