日期:2014-05-17  浏览次数:20521 次

如何抓取网页实时内容

#网址:http://data.shishicai.cn/cqssc/haoma/
#Demo:
<?php
/* Created on [2013-5-1] Author[Newton] Filename[action.php]*/
#编码转换
function convToUtf8($str) {
if (mb_detect_encoding($str, "UTF-8, ISO-8859-1, GBK") != "UTF-8") {
return iconv("GBK", "utf-8", $str);
} else {
return $str;
}
}

header("content-type:text/html;charset:utf-8");
error_reporting(E_ERROR);
$pages = file_get_contents('http://data.shishicai.cn/cqssc/haoma/');
//$pages = htmlspecialchars($pages);
$pages = convToUtf8($pages);
echo "pages-->>".print_r($pages);echo PHP_EOL;
$doc = new DOMDocument();
$new_doc = new DOMDocument('1.0', 'utf-8');

echo "doc-->>".print_r($doc);echo PHP_EOL;
$dom = $doc->getElementsByTagName('table');

$newdoc = $new_doc->loadhtml($dom->item(2)->nodeValue);
$table = $new_doc->saveHTML();
echo "table-->>{$table}".PHP_EOL;

#result:
#……乱码……
#pages-->>1 DOMDocument Object ( ) doc-->>1 table-->>
#table是空的……
?>
PHP DOM

------解决方案--------------------
页面数据是JS填充的。你得爬那个JS脚本。
------解决方案--------------------
貌似是用了frame框架内嵌在tbody里面,然后用JS代码来做html。
打开http://datacache.shishicai.cn/script/2f67117ba1b58074.js后,
搜索'frame'出来6条结果
凭我的技术分析是不出框架的链接

LZ看来也是位大神,技术分好高,仰望ING

------解决方案--------------------
http://data.shishicai.cn/handler/kuaikai/data.ashx
post: lottery=4&date=2013-05-06
采集这儿.