首页 技术 正文
技术 2022年11月15日
0 收藏 809 点赞 3,377 浏览 1269 个字

python爬虫快递查询系统(源码)

import requests
import jsondef get_express_type(postid):
'''根据快递单号来智能判断快递类型'''
url = 'http://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=%s' % (postid,) # 这里可以用元组这样保证的数据的安全性
# 把构造后的url通过requests请求来得到相应的数据是一个json数据
rs = requests.get(url)
# 再用json库中的loads数据来进行分析得到一个可用字典的方式来访问
kd_type_info = json.loads(rs.text)
kd_type = kd_type_info['auto'][0]['comCode']
return kd_type, postiddef execute_data_query(type, postid):
'''执行数据查询程序''' # 通过构造一个真正的url地址
url = 'http://www.kuaidi100.com/query?type=%s&postid=%s' % (type, postid) # 这里可以用元组这样保证的数据的安全性
# 把构造后的url通过requests请求来得到相应的数据是一个json数据
rs = requests.get(url)
# 再用json库中的loads数据来进行分析得到一个可用字典的方式来访问
kd_info = json.loads(rs.text)
msg = kd_info['message']
# 判断是否成功获取到了json的数据,如果有数据则进行下一步的解析
if msg == 'ok':
print('您的快递%s物流信息如下:' % postid)
data = kd_info['data']
for data_dict in data:
time = data_dict['time']
context = data_dict['context']
print('时间:%s %s' % (time, context))
else:
if msg == '参数错误':
print('您输入信息有误,请重输:')
else:
print(msg)def main():
'''快递查询主程序'''
while True:
print('**欢迎您登录快递查询系统**')
print('-' * 30)
print('** 1. 请输入您的快递单号 **')
print('** 0. 退出查询系统 **')
print('-' * 30)
order = input('查询请输入1退出请输入0:')
if order == '1':
# 进行快递查询操作
postid = input('请输入您的快递单号:')
type, postid = get_express_type(postid)
execute_data_query(type, postid)
elif order == '0':
exit()
else:
print('!!!!!您的指令输入有误,请重新输入:<---------')if __name__ == '__main__':
main()
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,033
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862