您好,登錄后才能下訂單哦!
這篇文章主要介紹“Python爬蟲怎么實現全國失信被執行人名單查詢功能”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Python爬蟲怎么實現全國失信被執行人名單查詢功能”文章能幫助大家解決問題。
一、需求說明
利用百度的接口,實現一個全國失信被執行人名單查詢功能。輸入姓名,查詢是否在全國失信被執行人名單中。
二、python實現
版本1:
# -*- coding:utf-8*- import sys reload(sys) sys.setdefaultencoding('utf-8') import time import requests time1=time.time() import pandas as pd import json iname=[] icard=[] def person_executed(name): for i in range(0,30): try: url="https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=6899" \ "&query=%E5%A4%B1%E4%BF%A1%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E5%90%8D%E5%8D%95" \ "&cardNum=&" \ "iname="+str(name)+ \ "&areaName=" \ "&pn="+str(i*10)+ \ "&rn=10" \ "&ie=utf-8&oe=utf-8&format=json" html=requests.get(url).content html_json=json.loads(html) html_data=html_json['data'] for each in html_data: k=each['result'] for each in k: print each['iname'],each['cardNum'] iname.append(each['iname']) icard.append(each['cardNum']) except: pass if __name__ == '__main__': name="郭**" person_executed(name) print len(iname) #####################將數據組織成數據框########################### data=pd.DataFrame({"name":iname,"IDCard":icard}) #################數據框去重#################################### data1=data.drop_duplicates() print data1 print len(data1) #########################寫出數據到excel######################################### pd.DataFrame.to_excel(data1,"F:\\iname_icard_query.xlsx",header=True,encoding='gbk',index=False) time2=time.time() print u'ok,爬蟲結束!' print u'總共耗時:'+str(time2-time1)+'s'
三、效果展示
"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/全國失信被執行人查詢.py
郭** 34122319790****5119
郭** 32032119881****2419
郭** 32032119881****2419
3
IDCard name
0 34122319790****5119 郭**
1 32032119881****2419 郭**
2
ok,爬蟲結束!
總共耗時:7.72000002861s
Process finished with exit code 0
版本2:
# -*- coding:utf-8*- import sys reload(sys) sys.setdefaultencoding('utf-8') import time import requests time1=time.time() import pandas as pd import json iname=[] icard=[] courtName=[] areaName=[] caseCode=[] duty=[] performance=[] disruptTypeName=[] publishDate=[] def person_executed(name): for i in range(0,30): try: url="https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?resource_id=6899" \ "&query=%E5%A4%B1%E4%BF%A1%E8%A2%AB%E6%89%A7%E8%A1%8C%E4%BA%BA%E5%90%8D%E5%8D%95" \ "&cardNum=&" \ "iname="+str(name)+ \ "&areaName=" \ "&pn="+str(i*10)+ \ "&rn=10" \ "&ie=utf-8&oe=utf-8&format=json" html=requests.get(url).content html_json=json.loads(html) html_data=html_json['data'] for each in html_data: k=each['result'] for each in k: print each['iname'],each['cardNum'],each['courtName'],each['areaName'],each['caseCode'],each['duty'],each['performance'],each['disruptTypeName'],each['publishDate'] iname.append(each['iname']) icard.append(each['cardNum']) courtName.append(each['courtName']) areaName.append(each['areaName']) caseCode.append(each['caseCode']) duty.append(each['duty']) performance.append(each['performance']) disruptTypeName.append(each['disruptTypeName']) publishDate.append(each['publishDate']) except: pass if __name__ == '__main__': name="郭**" person_executed(name) print len(iname) #####################將數據組織成數據框########################### # data=pd.DataFrame({"name":iname,"IDCard":icard}) detail_data=pd.DataFrame({"name":iname,"IDCard":icard,"courtName":courtName,"areaName":areaName,"caseCode":caseCode,"duty":duty,"performance":performance,\ "disruptTypeName":disruptTypeName,"publishDate":publishDate}) #################數據框去重#################################### # data1=data.drop_duplicates() # print data1 # print len(data1) detail_data1=detail_data.drop_duplicates() # print detail_data1 # print len(detail_data1) #########################寫出數據到excel######################################### pd.DataFrame.to_excel(detail_data1,"F:\\iname_icard_query.xlsx",header=True,encoding='gbk',index=False) time2=time.time() print u'ok,爬蟲結束!' print u'總共耗時:'+str(time2-time1)+'s'
關于“Python爬蟲怎么實現全國失信被執行人名單查詢功能”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。