Home  >  Article  >  Backend Development  >  携程api开发解决方法

携程api开发解决方法

WBOY
WBOYOriginal
2016-06-13 12:02:311446browse

携程api开发

本帖最后由 lziyanl 于 2014-06-03 13:53:29 编辑

如何获取上图的内容信息?在携程没找到对应接口,询问官方群,基本不搭理!
------解决方案--------------------
CURL用过没
------解决方案--------------------
源码里如果有内容的话应该是可以抓取吧
------解决方案--------------------
官方群不搭理是正常的,你采集别人的东西,对别人服务器增加压力。当然不会搭理你。



<br /><?php<br />$content = file_get_contents('http://www.ctrip.com/');<br />$pos1 = strpos($content, '<div class="vac_item vac_item_main">');<br />$pos2 = strpos($content, '<div id="guessvacation_list" class="h2tab_cn"   style="max-width:90%"></div>');<br />$content = substr($content, $pos1, $pos2-$pos1);<br /><br />// href<br />preg_match_all('/<a.*?href="((http(s)?:\/\/).*?)".*?/si', $content, $matches);<br />$href = array_values(array_unique($matches[1]));<br /><br />// src<br />preg_match_all('/_src=\"(.*?)\"/i', $content, $matches);<br />$src = $matches[1];<br /><br />// title<br />preg_match_all('/title=\"(.*?)\"/i', $content, $matches);<br />$title = $matches[1];<br /><br />// price<br />preg_match_all('/<span class=\"c_price\">(.*?)<\/span>/i', $content, $matches);<br />$price = $matches[1];<br /><br />$data = array();<br /><br />for($i=0,$len=count($href); $i<$len; $i++){<br />    $data[] = array(<br />        'href' => $href[$i],<br />        'src' => $src[$i],<br />        'title' => $title[$i],<br />        'price' => $price[$i],<br />    );<br />}<br /><br />print_r($data);<br />?><br />


<br><br>Array<br>(<br>    [0] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p1833645.html<br>            [src] => http://pkgpic.ctrip.com/images2/1/152/152_3391_g07660.jpg<br>            [title] => 【限量热卖!亲子套票(父亲节6.14-15)】广州长隆水上乐园门票(购票享5大特权!)<br>            [price] => 285<br>        )<br><br>    [1] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p1655820.html<br>            [src] => http://pkgpic.ctrip.com/images2/1/152/152_1660_g07660-m.jpg<br>            [title] => 广州塔观光门票(景区现付)<br>            [price] => 135<br>        )<br><br>    [2] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p83829.html<br>            [src] => http://pkgpic.ctrip.com/images2/1/152/152_3331_g07660-m.jpg<br>            [title] => 广州岭南印象园景区门票(景区现付)<br>            [price] => 30<br>        )<br><br>    [3] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p1811853.html<br>            [src] => http://pkgpic.ctrip.com/images2/1/27/27_523_g07660-m.jpg<br>            [title] => 【热卖!】广东珠海横琴长隆国际海洋度假区门票(各景区)<br>            [price] => 100<br>        )<br><br>    [4] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p84788.html<br>            [src] => http://pkgpic.ctrip.com/images2/1/152/152_919_s28632-m.jpg<br>            [title] => 广州海洋馆门票<br>            [price] => 120<br>        )<br><br>    [5] => Array<br>        (<br>            [href] => http://vacations.ctrip.com/tickets/p1659651.html<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn