利用python查询港澳通行证办理进度,python港澳通行证,分享原创的一段查询港澳通
利用python查询港澳通行证办理进度,python港澳通行证,分享原创的一段查询港澳通
分享原创的一段查询港澳通行证办理进度查询的python 3.3代码。利用socket请求相关网站,获得结果后利用正则找出办理进度。
import socketimport re'''广东省公安厅出入境政务服务网护照,通行证办理进度查询。分析网址格式为 http://www.gdcrj.com/wsyw/tcustomer/tcustomer.do?&method=find&applyid=身份证号码构造socket请求网页html,利用正则匹配出查询结果'''def gethtmlbyidentityid(identityid): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'www.gdcrj.com'; suburl = '/wsyw/tcustomer/tcustomer.do?&method=find&applyid={0}' port = 80; remote_ip = socket.gethostbyname(host) s.connect((remote_ip , port)) print('【INFO】:socket连接成功') message = 'GET '+ suburl.format(identityid) +' HTTP/1.1\\r\\nHost: '+ host +'\\r\\n\\r\\n' # str 2 bytes m_bytes = message.encode('utf-8') # send bytes s.sendall(m_bytes) print('【INFO】:远程下载中...') recevstr = '' while True: # return bytes recev = s.recv(4096) # bytes 2 str recevstr += recev.decode(encoding = 'utf-8', errors = 'ignore') if not recev: s.close() print('【INFO】:远程下载网页完成') break return recevstr'''利用正则表达式从上步获取的网页html内容里找出查询结果'''def getresultfromhtml(htmlstr): linebreaks = re.compile(r'\\n\\s*') space = re.compile('( )+') resultReg = re.compile(r'\\<td class="news_font"\\>([^<td]+)\\</td\\>', re.MULTILINE) #去除换行符和空格 htmlstr = linebreaks.sub('', htmlstr) htmlstr = space.sub(' ', htmlstr) #匹配出查询结果 result = resultReg.findall(htmlstr) for res in result: print(res.strip())if __name__ == '__main__': identityid = input('输入您的身份证号码(仅限广东省居民查询):') try: identityid = int(identityid) print('【INFO】:开始查询') html = gethtmlbyidentityid(identityid) getresultfromhtml(html) print('【INFO】:查询成功') except: print('【WARN】:输入非法') input('【INFO】:按任意键退出')#该片段来自于http://byrx.net
相关内容
- python获取每个月的第一天,python获取每个月,>>>
- 基于用户的协同过滤算法,用户协同过滤算法,本代码是
- python获得本机非127.0.0.1的ip地址,python机非,python获得本
- PyQt写的图片浏览器,PyQt写图片浏览器,开发环境: Cent
- 利用bs4获取58同城城市分类,bs4获取58同城,bs4的一些基
- 下载豆瓣友邻相册,豆瓣友邻相册,开发环境:WIn7,P
- 话说python的数据结构真的很适合快速排序啊,python数据
- 随机生成中文验证码的python代码,中文验证码python,#
- 关于Tk中Treeview的使用方法,tktreeview,#python3.3关于
- 爬虫 爬取网址,爬虫网址,爬取网页上的链接 然后分
评论关闭