0

I have to download file, I see I can do it using "urllib2".

response = urllib2.urlopen(URL)
file=response.read()

But, I can't read line by line.

Here's what I tried:

response = urllib2.urlopen(URL)
for line in response.read():
    #do stuff

All the file is one line. The original file was split by new lines.

Can someone tell me how to change the file to be like the original one?

3
  • Could you edit your question to include sample data? Commented Feb 22, 2016 at 15:13
  • response = urllib2.urlopen('mirror1.malwaredomains.com/files/domains.txt') for line in response.read(): Commented Feb 22, 2016 at 15:16
  • Sorry, maybe I was not clear, could you add example data from the webpage you are opening? Commented Feb 22, 2016 at 15:17

1 Answer 1

1

Just split the output:

response = urllib2.urlopen(URL)
lines=response.read().splitlines()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.