【发布时间】:2015-01-31 22:10:58
【问题描述】:
我正在尝试使用 curl 从网站上获取内容。我得到的错误是。
“在访问 roosterteeth.com 之前检查您的浏览器”
我尝试在 curl 中更改不同的属性,但仍然没有运气。我曾尝试使用 PHP Simple HTML Dom Parser,但又一次没有运气。
下面是我当前的代码。
<?php
$divContents = array();
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$html = curl_init("http://roosterteeth.com/home.php");
curl_setopt($html, CURLOPT_RETURNTRANSFER, true);
curl_setopt($html, CURLOPT_BINARYTRANSFER, true);
curl_setopt($html, CURLOPT_USERAGENT, $userAgent);
curl_setopt($html, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($html);
foreach($content->find("div.streamIndividual") as $div) {
$divContents[] = $div->outertext; }
file_put_contents("cache.htm", implode(PHP_EOL, $divContents));
$hash = file_get_contents("pg_1_hash.htm");
$cache = file_get_contents("cache.htm");
if ($hash == ($pageHash = md5($test))) {
} else {
$fpa = fopen("pg_1.htm", "w");
fwrite($fpa, $cache);
fclose($fpa);
$fpb = fopen("pg_1_hash.htm", "w");
fwrite($fpb, $pageHash);
fclose($fpb);
}
?>
由于 find 命令无法获取任何内容,因此上面的代码显示了不同的错误。下面的代码显示了我从该站点得到的错误。
<?php
$divContents = array();
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$html = curl_init("http://roosterteeth.com/home.php");
curl_setopt($html, CURLOPT_RETURNTRANSFER, true);
curl_setopt($html, CURLOPT_BINARYTRANSFER, true);
curl_setopt($html, CURLOPT_USERAGENT, $userAgent);
curl_setopt($html, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($html);
echo $content;
?>
我对这个错误的预感是服务器认为我是一个机器人(我不怪它相信这一点)。我使用 curl 来查看是否可以伪装成客户并绕过检查器,但没有成功。我希望有人能对此有所了解。
对于视觉错误,请单击此link.
感谢您的宝贵时间:)
【问题讨论】:
-
站点检查cookies,如果不存在,设置cookies并重定向浏览器....您需要激活cookies进行CURL传输。但看起来 cookie 将由 javascript 设置...