0

我想使用英国的代理 ip 浏览网站。

这可以在php中实现吗?如果是,请告诉我

4

1 回答 1

2

可以跟随代理。更好的方法是使用VPN。

但如果你想要代理,有一些网站,例如http://www.hidemyass.com

您可以随时从位于英国的 php 服务器下载网站并保存或显示。我还在这个网站上找到了代理http://www.fromzerotoseo.com/scraping-websites-php-curl-proxy/的示例

<?php
function getPage($proxy, $url, $referer, $agent, $header, $timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);

curl_close($ch);

return $result;
}
?>

用法:

 $result = getPage(
'[proxy IP]:[port]', // use valid proxy
'http://www.google.com/search?q=twitter',
'http://www.google.com/',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8',
1,
5);
于 2013-05-08T12:08:20.953 回答