[英]how to make php script use a list of proxies
我正在使用此處找到的 Google pagerank 檢查腳本:
http://www.off-soft.net/en/develop/php/prcheck.html
但是我注意到,在請求過多之后,服務器會被臨時禁止。
我想以某種方式通過代理服務器列表路由請求 - 任何人都可以讓我開始嗎?
我正在尋找使用代理列表的 php 請求的任何代碼示例。
謝謝!!
PHP 的 curl庫允許您使用 socks5 和 http 代理。 代理服務器列表應在使用前使用YAPH 等工具進行驗證。
臨時禁令是為了防止濫用。 使用代理繞過禁令並不是一件好事。 因此,您不太可能在這里找到可以幫助您違反該網站 TOS 的人。
話雖如此,HTTP 代理只是一個網絡服務器,它將處理/尊重對外部/外部 URL 的請求並返回結果。 其余的留給提問者作為練習。
如果您不介意使用付費 API,那么 gimmeproxy.com 將為您服務。
<?php
function getProxy() {
$data = json_decode(file_get_contents('http://gimmeproxy.com/api/getProxy?api_key=YOUR_API_KEY'), 1);
if(isset($data['error'])) { // there are no proxies left for this user-id and timeout
echo $data['error']."\n";
}
return isset($data['error']) ? false : $data['curl']; //gimmeproxy returns 'curl' field that is CURLOPT_PROXY-ready string, see curl_setopt($curl, CURLOPT_PROXY, $proxy);
}
function get($url) {
$curlOptions = array(
CURLOPT_CONNECTTIMEOUT => 5, // connection timeout, seconds
CURLOPT_TIMEOUT => 10, // total time allowed for request, second
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYPEER => false, // don't verify ssl certificates, allows https scraping
CURLOPT_SSL_VERIFYHOST => false, // don't verify ssl host, allows https scraping
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 9, // max number of redirects
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => 0,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
CURLINFO_HEADER_OUT => true,
);
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
if($proxy = getProxy()) {
echo 'set proxy '.$proxy."\n";
curl_setopt($curl, CURLOPT_PROXY, $proxy);
}
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
while(true) {
$data = get('https://news.ycombinator.com/');
if(trim($data) && stripos($data, 'Hacker News') !== false) {
echo "hacker news works fine";
break;
} else {
echo "hacker news banned us, try another proxy\n";
}
}
使用 Squid 代理的示例 PHP CURL 請求:
$proxy = "1.1.1.1:12121";
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$url = "http://www.google.pt/search?q=anonymous";
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,15);
curl_setopt($ch, CURLOPT_HTTP_VERSION,'CURL_HTTP_VERSION_1_1' );
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD,'USER:PASS');
curl_setopt($ch, CURLOPT_USERAGENT,$useragent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
$result = curl_exec ($ch);
curl_close ($ch);
在此處了解如何使用旋轉傳出 ip 實現您自己的魷魚代理
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.