Python小应用之火车路线查询
2010-04-26 15:12
316 查看
代码def getrain(f,t):
"""获取火车路线,参数是from和to"""
url ="http://wap.huochepiao.com/cx/"
form = urllib.urlencode([('chufa',f),('daoda',t)])
req = urllib2.Request(url)
fd = urllib2.urlopen(req,form)
lines = fd.readlines()
cars = str(lines[16])
cars = cars.replace("<b>","")
cars = cars.replace("</b>","")
cars = cars.replace("<br />","")
print cars.decode("utf-8")
lines = lines[20:-6]
tmp = ""
for l in lines:
tmp = tmp + l
tmp = tmp.replace("<br />","")
tmp = tmp.replace("<li>","")
tmp2 = tmp.split("\r\n\r\n")
tmp3 = []
for i in tmp2:
i = i.strip()
if i == "":
continue
pos1 = i.rfind("=") + 1
pos2 = i.rfind('"')
cc = "车次:%s" % i[pos1:pos2]
i = i[i.find("\n",2)+1:]
i = cc + "\n" + i + "\r\n"
tmp3.append(i)
end = ""
for s in tmp3:
end = end + s + "\n"
end = cars + end + "\n"
return end
拿过去就可以用, 前面需要:
import string
import urllib
import urllib2
import sys
主要思路:
1、就是找个wap查询火车的网站,发现还不错
2、抓包,看到post的数据
3、然后在模拟提交,下载
4、解析,输出
拿过去就可以用,输出已经做过处理
"""获取火车路线,参数是from和to"""
url ="http://wap.huochepiao.com/cx/"
form = urllib.urlencode([('chufa',f),('daoda',t)])
req = urllib2.Request(url)
fd = urllib2.urlopen(req,form)
lines = fd.readlines()
cars = str(lines[16])
cars = cars.replace("<b>","")
cars = cars.replace("</b>","")
cars = cars.replace("<br />","")
print cars.decode("utf-8")
lines = lines[20:-6]
tmp = ""
for l in lines:
tmp = tmp + l
tmp = tmp.replace("<br />","")
tmp = tmp.replace("<li>","")
tmp2 = tmp.split("\r\n\r\n")
tmp3 = []
for i in tmp2:
i = i.strip()
if i == "":
continue
pos1 = i.rfind("=") + 1
pos2 = i.rfind('"')
cc = "车次:%s" % i[pos1:pos2]
i = i[i.find("\n",2)+1:]
i = cc + "\n" + i + "\r\n"
tmp3.append(i)
end = ""
for s in tmp3:
end = end + s + "\n"
end = cars + end + "\n"
return end
拿过去就可以用, 前面需要:
import string
import urllib
import urllib2
import sys
主要思路:
1、就是找个wap查询火车的网站,发现还不错
2、抓包,看到post的数据
3、然后在模拟提交,下载
4、解析,输出
拿过去就可以用,输出已经做过处理
相关文章推荐
- python 3.6 tkinter+urllib+json 火车车次信息查询
- python火车余票查询(s5)
- python火车余票查询(s10)
- Python-web: Flask 应用、数据库查询数据、API接口
- python 工具化查询苹果送审页面iTunes Connect的应用的各种信息
- python火车余票查询(s1)
- python火车余票查询(stationapi)
- Python大法之从火车余票查询到打造抢Supreme神器
- 已解决:百度地图的查询驾车路线,集成到应用里面无法画出路线,无法得到MKSearchListener的结果
- 火车余票查询应用代码分享
- python全栈学习路线-查询笔记
- Python rPyc 模块应用:在远端上执行命令,并且获取查询结果
- python 3.6 tkinter+urllib+json实现火车车次信息查询功能
- 再来一个PYTHON小应用:天气查询
- Python大法之从火车余票查询到打造抢Supreme神器
- 根据两个经纬度点调用百度地图应用查询路线 适用android或者ios中及网页浏览(手机网页同样适用)
- python numpy和list查询其中某个数的个数及定位方法
- python解释器实现及其嵌入式应用:一个四则运算计算器的实现
- 在 Python 应用中使用 MongoDB的方法
- Python3.5——装饰器及应用详解(上)