• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

他们在爬网页时,是怎么用的代理IP?

php 搞代码 3年前 (2022-01-25) 13次浏览 已收录 0个评论
文章目录[隐藏]

比如用CURL的话,代理IP该怎么用啊,是开启软件还是直接在CURL做的设置啊,求指教。

回复内容:

!本文来源gaodai#ma#com搞*!代#%^码网5

搞gaodaima代码

比如用CURL的话,代理IP该怎么用啊,是开启软件还是直接在CURL做的设置啊,求指教。

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

<code>php</code><code>if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);</code>

<code>    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. 设置选项,包括URL        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         curl_setopt($ch, CURLOPT_HEADER, 0);         curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:61.135.169.125', 'CLIENT-IP:61.135.169.125'));  //构造IP        curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/");   //构造来路        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');        if($autoFollow){            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  //启动跳转链接            curl_setopt($ch, CURLOPT_AUTOREFERER, true);  //多级自动跳转        }           //          if($post!=''){            curl_setopt($ch, CURLOPT_POST, 1);//post提交方式            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);        }           // 3. 执行并获取HTML文档内容        $output = curl_exec($ch);        curl_close($ch);        return $output;    }</code>

CURLOPT_HTTPHEADER,

写爬虫必备


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:他们在爬网页时,是怎么用的代理IP?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址