Python download File & anti-theft chain

Source: Internet
Author: User

Accidentally download a type of resources, found a lot of pages, right-click Save What, Patience.

decided to write a few lines of code in Python. The core code is as follows:

From urllib import urlretrievefrom urllib import Urlretrieveurlretrieve (url,save_to_path,show_download_progress)    

As for the URL, simply use the crawler to get the idea. Not the focus of this article, no longer verbose.

The problem is, I don't know why, all the downloaded files are 42k!

Think of the solution, should be a certain limit, the head is not bright, thought for a long while to think, should be the chain of anti-theft.

Check the next, so with Wireshark simulation, found that the header parameters too many, not good each to set (depending on the person's website logical design), so regardless of 3,721, first gave a reffer.

Unfortunate success. Well, no more research, no more work, no more records.

Solutions to the above problems:

Import urllib2req = Urllib2. Request (' http://www.example.com/') req.add_header (' Referer ', ' http://www.python.org/') resp = Urllib2.urlopen (req) Content = Resp.read ()

Next, just need the content to write to the file inside, just a little.

Python download File & anti-theft chain

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.