CI CURL採集问题,高手赐教
本帖最后由 bax 于 2013-2-24 00:19 编辑我想采集一个网站简单的table内容http://www.malaysiaairlines.com/content/mas/my/en/book-and-plan/flight-status/jcr:content/contentpar/flightstatussearch_0.processSearch.html/?flightdate=02/24/2013&flightfrom=MYY我只要时间表..我尝试过用以下方法,但是网上说CURL的效率比较快...有哪位高手可以教教我,网址中的日期记得自行更改成 昨天/今天/明天,否则无效
$url="http://www.malaysiaairlines.com/content/mas/my/en/book-and-plan/flight-status/jcr:content/contentpar/flightstatussearch_0.processSearch.html/?flightdate=02/24/2013&flightfrom=MYY";
$result = file_get_contents($url);
$pattern = '/<tbody>([^"]+)<\/tbody>/';
preg_match_all($pattern, $result, $arr);
function curl_get_content( $url )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //Set access url adress
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Set timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Ser return value
$r = curl_exec($ch); //Set $r
curl_close($ch); //Close curl function
return $r; //Return data
}
$url="http://www.malaysiaairlines.com/content/mas/my/en/book-and-plan/flight- status/jcr:content/contentpar/flightstatussearch_0.processSearch.html/?flightdate=02/24/2013&flightfrom=MYY";
$result = curl_get_content($url);
$pattern = '/<tbody>([^"]+)<\/tbody>/';
preg_match_all($pattern, $result, $arr);
把CURL操作封装起来,基本上木有什麽困难。
可以参考UDSync用的方式。
页:
[1]