Use Curl to crawl Web site data, imitation IP, anti-blocking the ultimate powerful solution

Source: Internet
Author: User

Recently do some crawl other website data work, of course, others will not be a free to you scratch data, there are various anti-crawling methods. But however persuasive, outsmart, through the study are loopholes can be drilled. The following examples are written in PHP, do not use PHP to Curl child paper first learn this piece and then look down, you can refer to this article: http://blog.csdn.net/linglongwunv/article/details/8020845

Below the bottom, first say a common way, forged source IP, which is also a lot of friends to brush tickets common methods:

1, a simple point can be forged in the header x-forwarded-for, and forged Referer, the code is as follows:

[PHP]View Plaincopy
    1. curl_setopt ($ch, Curlopt_httpheader, Array (' x-forwarded-for:111.222.333.4 ', ' Client-ip  : 111.222.333.4 '));
    2. curl_setopt ($ch, Curlopt_referer, "http://www.test.com");


2, the above method most can fool over, but also have caught the real IP. In the use of proxies, the trouble is that you have a valid proxy IP and port number, and some also need a user name password, the code is as follows:

[PHP]View Plaincopy
    1. curl_setopt ($ch, Curlopt_proxy, "http://111.222.333.4:110");


In addition, there is a situation, that is, with the browser can access, with curl is not, found that the other side checked the useragent, if not considered to be crawling and other illegal sources, then we will add useragent in the header, the code is as follows:

[PHP]View Plaincopy
      1. curl_setopt ($ch, curlopt_useragent, "mozilla/5.0 (Windows NT 6.1) applewebkit/536.11 (khtml, like Gecko) chrome/ 20.0.1132.57 safari/536.11 ");

Use Curl to crawl Web site data, imitation IP, anti-blocking the ultimate powerful solution

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.