Save file from web python




















Harikrishna this is probably problem in Python 3 and this case is answered here: stackoverflow. The Aelfinn The Aelfinn This is one great solution! Thank you The Aelfinn! Great solution, but I had to also import codecs and wrap the r. I was looking for a solution like this, with requests. I like this solution a lot — mit. It's now necessary to decode urlopen 's response in bytes into a valid local encoding, so the accepted answer has to be modified slightly: import csv, urllib.

Thank you ThedudeAbides for providing an updated solution! Just want to add that import pandas alone will be an order of magnitude slower than any other solution on this page.

So don't go pip install pandas JUST because you see that you can do a cool one-liner with it; it also brings in numpy as a dependency, and it's all downhill from there.

Same goes for import requests , although not to such a degree. I am also using this approach for csv files Python 3. StringIO r. DictReader buff for row in dr: print row. Michal Skop Michal Skop 1, 1 1 gold badge 14 14 silver badges 21 21 bronze badges. Adeshina Otayo Adeshina Otayo 9 1 1 bronze badge. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog.

Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.

Well, you can at least try to download and process the file in chunks: stackoverflow. Possible duplicate of In Python, given a URL to a text file, what is the simplest way to read the contents of the text file? Show 2 more comments. Active Oldest Votes. Tai Tai 6, 3 3 gold badges 23 23 silver badges 42 42 bronze badges.

Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. That's perfect! Thank you so much! I don't know why requests module could complete that while urllib and urllib2 cannot do that, but anyways. Cleb That's not an image — Shidouuu.

Python 3 import urllib. Ankit Lad Ankit Lad 1 1 silver badge 5 5 bronze badges. Basil Jose Basil Jose 10 10 silver badges 11 11 bronze badges. Welcome to Stackoverflow and thanks for your contribution!

Could you add an explanation to your answer what the code does and why it works? How do I add the headers for url in urlretrieve? I had a problem with images opening in the browser but not through code using urlretrive. I have tried urlopen but I don't know how to download the image using urlopen. Ssubrat Rrudra Ssubrat Rrudra 6 6 silver badges 17 17 bronze badges. Vicrobot Vicrobot 3, 1 1 gold badge 13 13 silver badges 29 29 bronze badges.

That gives me an empty image for the following URL: genome. Cleb That's because the url you provided doesn't belong to an image. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta.



0コメント

  • 1000 / 1000