百度首页 | 百度空间
 
查看文章
 
php 解析html
2008-04-17 11:38

php 解析html


<
require_once('../const.inc.php');
$fc=$_GET["fc"];
$tc=$_GET["tc"];
$type=$_GET["type"];
$d=$_GET["d"];
$t=$_GET["t"];
$c=$_GET["c"];
function get_content($url)
{
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    ob_start();
    curl_exec ($ch);
    curl_close ($ch);
    $string = ob_get_contents();
    ob_end_clean();
   
    return $string;    
}
function find($content,$b,$e,$flag)
{
if ($flag===1)
{
   $content =iconv('gb2312', 'UTF-8',$content);
   $b =iconv('gb2312', 'UTF-8',$b);
   $e =iconv('gb2312', 'UTF-8',$e);
}
$view = array();
$i=0;
while (strpos($content,$b)!== false)
{
    $content_new = substr($content,strpos($content, $b)+strlen($b));
    $view[$i] =substr($content_new,0,strpos($content_new, $e));
    $content = substr($content_new,strlen($view[$i]));
    $i++;
}
return $view;
}
//取出数据
$date = substr($d,0,4)."-".substr($d,4,2)."-".substr($d,6,2);
$content = get_content("http://www.etpass.com/OnlineOrder/FlightList.aspx type=".$type."&sort=1&fc=".$fc."&tc=".$tc."&fc1=&tc1=&d=".$date."&t=".$t."&bd=&bt=&c=".$c."&All=1");
//$index = strpos($content,"EtmcQueryObject_dgAirline");
//$content = substr($content,$index,strlen($content)-$index);
//$content = get_content("http://www.etpass.com/OnlineOrder/FlightList.aspx type=1&sort=1&fc=BBB&tc=SSS&fc1=&tc1=&d=2007-08-02&t=&bd=&bt=&c=&All=1");
$lblDepTime = find($content,"lblDepTime">","</span>",0); //起飞时间
$lblDesTime = find($content,"lblDesTime">","</span>",0); //到达时间
$lblAirLine = find($content,"lblAirLine" class="tit2">","</span>",0); //航班名称
$price = find($content,"<td class="p03" nowrap="nowrap" align="Left"><b>","</b>",1); //价格
//$price = "";
$seat = find($content,"剩余座位<b>","</b>",1); //剩余座位
$num = count($lblDepTime);
session_start();
$_SESSION["lblDepTime"] = $lblDepTime;
$_SESSION["lblDesTime"] = $lblDesTime;
$_SESSION["lblAirLine"] = $lblAirLine;
$_SESSION["price"] = $price;
$_SESSION["seat"] = $seat;
$_SESSION["num"] = $num;
session_write_close();
header("Location: http://192.168.1.8/IPPhone/ticket/ticketImage.php");
>

类别:网页抓取技术的研究 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu