1

我想使用来自 TOR 网络后面的共享服务器(仅端口 80 和 443 开放)的 PHP cURL 进行屏幕抓取。我尝试下面的代码并从我的服务器收到“拒绝访问”错误,因为端口 8118 和 9050 已关闭。我联系了支持,他们说这是不可能的。我对此表示怀疑,但一直在寻找,找不到简单的解决方案。有什么想法吗?

     <?php
$fh = fopen('curldebug.txt','w') or die($php_errormsg);
// Initialize cURL
$ch = curl_init();

// Set the website you would like to scrape
curl_setopt($ch, CURLOPT_URL, "http://www.fixitts.com/whatismyip.php");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0');
curl_setopt($ch, CURLOPT_REFERER, 'http://www.fixitts.com');
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8118');

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fh);
 // Set cURL to return the results into a PHP variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// This executes the cURL request and places the results into a variable.
$curlResults= curl_exec($ch);

        if(curl_errno($ch))
        {
            echo 'Curl error: ' . curl_error($ch);
        }

        $info = curl_getinfo($ch);
        print_r ($info);

// Close curl
curl_close($ch);
fclose($fh) or die($php_errormsg);
// Echo the results to the screen>
echo $curlResults;

?>
4

2 回答 2

4

您的虚拟主机的支持可能是正确的。

附带说明一下,通过 TOR 进行屏幕抓取是一件非常反社会的事情。这是许多网站阻止来自已知 TOR 出口节点的访问的很大一部分原因。请停下。

于 2013-02-23T01:59:39.077 回答
0

我假设你有一个本地代理在 8118(Polipo 或 Privoxy)上监听。

端口 8118 和 9050 是 TOR 和 Polipo 在 localhost (127.0.0.1) 上默认使用的端口。
本地主机端口没有被共享服务器阻止 - 127.0.0.1 是您的 PC。如果它们被阻止,则您的 PC(防火墙)上有一些东西在这样做。

此外,您可以告诉 TOR 和 Polipo(或其他)在其配置文件中使用不同的端口。在上面的代码以及 Polipo/Privoxy 上将 8118 更改为其他内容。

共享服务器是否限制为 80 和 443 无关紧要。这就是 TOR 发送您的东西所需的全部内容。TOR 出口服务器解开它得到的任何东西,并查看它应该去的端口(原始目标端口)。

共享服务器可能会阻止端口 80 和 443 与已知 TOR 服务器的连接。打开浏览器,将代理设置为 SOCKS127.0.0.1 端口 9050,看看是否可以浏览网页。如果这不起作用,你可能有你的答案。您可以查看 TOR 文档。我记得他们在那里告诉你如何判断 TOR 是否被阻止。

于 2013-02-23T02:04:27.857 回答