Downloading a song through python-requests Ask Question. Asked 5 years, 3 months ago. Active 4 months ago. Viewed 9k times. Can't we use "requests" library to download songs? If yes, how? Shivam Mitra Shivam Mitra 2 2 gold badges 15 15 silver badges 30 30 bronze badges. Add a comment. Active Oldest Votes. Tiger Tiger 5, 3 3 gold badges 42 42 silver badges 56 56 bronze badges. Can you also explain the use of binary encoding rather than unicode?
Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast what if you could invest in your favorite developer? Who owns this outage? Building intelligent escalation chains for modern SRE. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Related Hot Network Questions.
Question feed. A naive way to do it will be -. It works but is not the optimum way to do so as it involves downloading the file for checking the header.
So if the file is large, this will do nothing but waste bandwidth. I looked into the requests documentation and found a better way to do it. That way involved just fetching the headers of a url before actually downloading it.
This allows us to skip downloading files which weren't meant to be downloaded. To restrict download by file size, we can get the filesize from the Content-Length header and then do suitable comparisons. We can parse the url to get the filename. This will be give the filename in some cases correctly. However, there are times when the filename information is not present in the url. In that case, the Content-Disposition header will contain the filename information.
So, this is one way to obtain useful data. After that, however, you still need to analyze it. That said, if you want to strengthen your analytical skillset, check out our complete Data Science program. It is designed to help you develop all in-demand competencies for a data scientist or a data analyst job. Nikola Pulev is a University of Cambridge graduate, a data science practitioner, and instructor at Data Science.
Career Track Certificate Course Certificate. Nikola Pulev. Learn data science with industry experts Try For Free.
0コメント