冰豆网

分享网络精彩
bingdou.com.cn

php抓取其它网站的动态数据,显示在自己的网页内并同步更新

时间:2019-07-07加入收藏

$url = "http://www.boc.cn/sourcedb/whpj/";
$queryServer = curl_init();
curl_setopt($queryServer, CURLOPT_URL, $url);
curl_setopt($queryServer, CURLOPT_HEADER, 0);
curl_setopt($queryServer, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($queryServer, CURLOPT_RETURNTRANSFER, true);
curl_setopt($queryServer, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($queryServer, CURLOPT_TIMEOUT, 30);
$html = curl_exec($queryServer);
$html = iconv('UTF-8','GBK//IGNORE',$html); //如果你需要是的数据是utf-8编码的,这一行可以注销,如果需要gbk编码的,请保留.如果出现乱码,就是一行的问题,你自己调着试吧
//echo $holder;exit; 此处可以输出来测试.
$html = str_replace(array("\n","\r","\t"),"",$html);
$preg = '/<table\s+width=\"800\"[^>]+>(.*?)<\/table>/';
preg_match_all($preg,$html,$out);
//匹配每行
preg_match_all('/<tr[^>]+>(.*?)<\/tr>/',$out[1][0],$tr);
//匹配每个td
$result = array();
$match = '/<td.+>([^<]+)<\/td>/U';
foreach( $tr[0] as $key => $value ){
preg_match_all($match,$value,$arr);
$result[] = $arr[1];
}
//输出测试,$result就是你要的数据,至于你要怎么输出显示格式,那就随心调就好了。
foreach( $result as $key => $value ){
echo implode("\t",$value);
echo "<br>";
}
exit;

打 赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

TGA: php

分享到:


官方微信二维码冰豆网官方微信公众号