爬取12306站点信息
来源:互联网 发布:机械模拟仿真软件 编辑:程序博客网 时间:2024/05/29 04:12
# -*- coding: utf-8 -*-import sslimport urllib2from prettytable import PrettyTabledef get_station_name(): url = "https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.9025" #目的为了通过未认证的12306证书 ssl._create_default_https_context = ssl._create_unverified_context req = urllib2.Request(url) req.add_header("Referer","https://kyfw.12306.cn/otn/leftTicket/init") req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36") names = urllib2.urlopen(req).read() with open("station_name0.txt", 'wb') as f: f.write(names) itemsTmp = names.split("'") if len(itemsTmp) == 3: items = itemsTmp[1].split("@") table = PrettyTable(["序号","中文名","车站代码","中文拼音","拼音首字母"]) table.header = True table.padding_width = 2 for item in items: if item == "": continue info = item.split("|") tr = [info[5],info[1],info[2],info[3],info[4]] table.add_row(tr) with open("station_name.txt", 'wb') as f: f.write(table.get_string()) if __name__ == "__main__": import sys reload(sys) sys.setdefaultencoding('utf-8') get_station_name()
阅读全文
1 0
- 爬取12306站点信息
- 1.1 爬下12306--爬取信息
- 爬取招聘信息
- 爬取二手房信息
- 大学排名信息爬取
- python爬取网页信息
- HttpClient 登录爬取信息
- 安居客信息爬取
- urllib2 爬取网页信息
- python3爬取淘宝信息
- python3爬取淘宝信息!
- 爬取二手房信息v2
- python 爬取淘宝信息
- 携程网旅游信息爬取
- Python爬取国家信息
- 爬取环境信息实例
- Python-爬取网页信息
- Python爬取天气信息
- 使用cmake gui 生成cpp-netlib vs2013项目并编译说明
- linux grep
- springMVC类型转换,提交日期字符数据自动转换日期格式
- NodeJs surperagent API
- 慕课笔记--[课程]Node.js+MongoDB建站攻略
- 爬取12306站点信息
- DBV-00201: Block, DBA 21065723, marked corrupt for invalid redo application解决
- amoy url
- 数组指针和指针数组的区别
- Spring思维导图,让Spring不再难懂(ioc篇)
- Bootstrap Modal-静态框使用及遇到的问题
- 求一组数中的最大最小数以及源码分析
- [DUBBO] Unexpected error occur at send statistic, cause: Forbid consumer 192.168.3.151 access servic
- linux find