How do they use the proxy IP address when crawling webpages?

Source: Internet
Author: User
For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise. For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise.

Reply content:

For example, if CURL is used, how can I use the proxy IP address? Can I enable the software or directly set the proxy IP address in CURL? Please advise.

Http://php.net/manual/en/book.curl.php

phpif ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);

Function curlPost ($ url, $ post = '', $ autoFollow = 0) {$ ch = curl_init (); $ user_agent = 'safari Mozilla/5.0 (Macintosh; intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/5 curl_setopt ($ ch, CURLOPT_USERAGENT, $ user_agent); // 2. set options, including URL curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); curl_setopt ($ ch, substring, array ('x-FORWARDED-FOR: 61.135.169.125 ', 'client-IP: 61.135.169.125'); // construct IP curl_setopt ($ ch, CURLOPT_REFERER," http://www.baidu.com/ "); // Construct curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, 'get'); if ($ autoFollow) {curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true ); // start the jump link curl_setopt ($ ch, CURLOPT_AUTOREFERER, true); // Multi-Level Automatic jump} // if ($ post! = '') {Curl_setopt ($ ch, CURLOPT_POST, 1); // The post submission method curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post);} // 3. execute and obtain the HTML document content $ output = curl_exec ($ ch); curl_close ($ ch); return $ output ;}

CURLOPT_HTTPHEADER,

Essential for Crawler writing

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.