我正在使用PHP试图抓取页面,似乎在父页面加载完成后仅仅几毫秒就动态加载内容。PHP:延迟解析页面源代码(通过file_get_html())1秒
我使用curl来解析页面,而simpleHtmlDom从解析的html中抓取事物。我的努力遍历DOM和爆炸()的东西出来的HTML返回什么都没有。我唯一的想法是加载了之后的加载了父页面。
这是我的代码。
<?
$url = 'http://www.facebook.com/OneAndroidAppaDay';
$scrapeUrl = 'http://www.facebook.com/OneAndroidAppaDay';
include_once('simple_html_dom.php');
require_once("bitly.php");
$userAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$scrapeUrl);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = curl_exec($ch);
if (!$html) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
$appBitlyUrl = $html->find('div[class=UIStoryAttachment_Title]',0)->find('a',0)->href; // fail :(
echo 'Bitly Url: ' . $appBitlyUrl;
?>
它与此错误轰炸了在第24行(与行内注释表示):
Fatal error: Call to a member function find() on a non-object in /home/xxxxxxxx/public_html/xxx.xx/xxxx.php on line 24
有没有办法让它等待一两秒钟就抢页面的HTML之前?或者,也许有人有更好的见解?
感谢
马克
任何类型的延迟都与您当前拥有的错误消息无关。 – zerkms 2010-11-13 03:39:39
顺便说一句,刮脸在Facebook的任何应用程序的内容是超出他们的TOS和非法,downvoted。 – zerkms 2010-11-13 03:40:15
Upvoted回零。这不是一个法律咨询网站。除了Facebook没有对用户贡献的内容拥有版权的权力之外,对个人使用的欺骗也很少是非法的。 (是的,我知道我也在做假设。) – mario 2010-11-13 04:11:43