我使用这个解决方案:
$aContext = array(
'http' => array(
'proxy' => 'tcp://192.168.0.2:3128',
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents("http://www.google.com", False, $cxContext);
echo $sFile;
如何更改脚本,以便使用代理列表而不是代理格式:
...
192.168.0.2:3128
193.123.8.2:3128
194.115.10.2:80
195.178.0.2:80
...
答案 0 :(得分:2)
嗯,你已经拥有了大部分代码,这就是我要做的事情:
<?php
$proxies = array( '192.168.0.2:3128', '192.168.8.2:3128', '192.168.10.2:80' );
// Pick a random proxy:
$proxy_to_use = $proxies[ rand( 0, count( $proxies ) -1 ];
$aContext = array(
'http' => array(
'proxy' => 'tcp://' . $proxy_to_use,
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents("http://www.google.com", False, $cxContext);
echo $sFile;
?>
这是你的想法吗?