Python 抓取 qunar 最低机票

# 感谢 hackcrisman@gmail.com 投递。

小白我今天为了拿刚入门的python练手,写了个比较有实用价值的脚本,可以帮大家省钱了。刚开始我对xml没有什么概念。网上了解了一下。主要是通过(http://woodpecker.org.cn/diveintopython3/xml.html )清楚了做法.

代码如下:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as etree
import urllib

context = urllib.urlopen('http://ws.qunar.com/holidayService.jcp?lane=上海-长沙')
tree = etree.parse(context)
root = tree.getroot()
for node in root[0]:
    if node.attrib["date"] == "2011-09-30":
        for child in node:
            for child_detail in child.attrib.keys():
                if child.attrib["type"] == "go" and int(child.attrib["price"])<600:
                print child_detail,child.attrib[child_detail]
                urllib.urlopen('http://api.sms.xxx.com/sms.jcp?c="有机票了"&p=138********'

说明下,那个时间(2011-09-30)是我要订日期,那个"go" 是去程的,他xml里也有从对方过来的,所以我过滤了
还有600 就是价钱啦.低于就发短信提醒你订票了。
短信接口就不说了。大家自行替换吧.
这个返回的xml好像只有40几天以内的信息哦.还有大家别忘了把要飞的地点的字符串替换掉. --___---!!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。