Python爬蟲(chóng)實(shí)現(xiàn)全國(guó)失信被執(zhí)行人名單查詢(xún)功能示例
本文實(shí)例講述了Python爬蟲(chóng)實(shí)現(xiàn)全國(guó)失信被執(zhí)行人名單查詢(xún)功能。分享給大家供大家參考,具體如下:
一、需求說(shuō)明
利用百度的接口,實(shí)現(xiàn)一個(gè)全國(guó)失信被執(zhí)行人名單查詢(xún)功能。輸入姓名,查詢(xún)是否在全國(guó)失信被執(zhí)行人名單中。

二、python實(shí)現(xiàn)
版本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)
#####################將數(shù)據(jù)組織成數(shù)據(jù)框###########################
data=pd.DataFrame({"name":iname,"IDCard":icard})
#################數(shù)據(jù)框去重####################################
data1=data.drop_duplicates()
print data1
print len(data1)
#########################寫(xiě)出數(shù)據(jù)到excel#########################################
pd.DataFrame.to_excel(data1,"F:\\iname_icard_query.xlsx",header=True,encoding='gbk',index=False)
time2=time.time()
print u'ok,爬蟲(chóng)結(jié)束!'
print u'總共耗時(shí):'+str(time2-time1)+'s'
三、效果展示
"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/全國(guó)失信被執(zhí)行人查詢(xún).py
郭** 34122319790****5119
郭** 32032119881****2419
郭** 32032119881****2419
3
IDCard name
0 34122319790****5119 郭**
1 32032119881****2419 郭**
2
ok,爬蟲(chóng)結(jié)束!
總共耗時(shí):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)
#####################將數(shù)據(jù)組織成數(shù)據(jù)框###########################
# 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})
#################數(shù)據(jù)框去重####################################
# data1=data.drop_duplicates()
# print data1
# print len(data1)
detail_data1=detail_data.drop_duplicates()
# print detail_data1
# print len(detail_data1)
#########################寫(xiě)出數(shù)據(jù)到excel#########################################
pd.DataFrame.to_excel(detail_data1,"F:\\iname_icard_query.xlsx",header=True,encoding='gbk',index=False)
time2=time.time()
print u'ok,爬蟲(chóng)結(jié)束!'
print u'總共耗時(shí):'+str(time2-time1)+'s'
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專(zhuān)題:《Python Socket編程技巧總結(jié)》、《Python正則表達(dá)式用法總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門(mén)與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
- Python實(shí)現(xiàn)爬取百度貼吧帖子所有樓層圖片的爬蟲(chóng)示例
- python爬蟲(chóng)_實(shí)現(xiàn)校園網(wǎng)自動(dòng)重連腳本的教程
- python爬蟲(chóng) 使用真實(shí)瀏覽器打開(kāi)網(wǎng)頁(yè)的兩種方法總結(jié)
- 一個(gè)簡(jiǎn)單的python爬蟲(chóng)程序 爬取豆瓣熱度Top100以?xún)?nèi)的電影信息
- python書(shū)籍信息爬蟲(chóng)實(shí)例
- 零基礎(chǔ)寫(xiě)python爬蟲(chóng)之爬蟲(chóng)編寫(xiě)全記錄
- Python爬蟲(chóng)框架Scrapy安裝使用步驟
- Python爬蟲(chóng)模擬登錄帶驗(yàn)證碼網(wǎng)站
- 零基礎(chǔ)寫(xiě)python爬蟲(chóng)之使用urllib2組件抓取網(wǎng)頁(yè)內(nèi)容
- 零基礎(chǔ)寫(xiě)python爬蟲(chóng)之使用Scrapy框架編寫(xiě)爬蟲(chóng)
- python模擬新浪微博登陸功能(新浪微博爬蟲(chóng))
相關(guān)文章
Python利用imshow制作自定義漸變填充柱狀圖(colorbar)
這篇文章主要介紹了Python利用imshow制作自定義漸變填充柱狀圖(colorbar),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
Python實(shí)現(xiàn)簡(jiǎn)單文本字符串處理的方法
這篇文章主要介紹了Python實(shí)現(xiàn)簡(jiǎn)單文本字符串處理的方法,涉及Python針對(duì)文本字符串的切割、計(jì)算、轉(zhuǎn)換等相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
django ajax發(fā)送post請(qǐng)求的兩種方法
這篇文章主要介紹了django ajax發(fā)送post請(qǐng)求的兩種方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01
pandas之分組統(tǒng)計(jì)列聯(lián)表pd.crosstab()問(wèn)題
這篇文章主要介紹了pandas之分組統(tǒng)計(jì)列聯(lián)表pd.crosstab()問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
python中自帶的三個(gè)裝飾器的實(shí)現(xiàn)
這篇文章主要介紹了python中自帶的三個(gè)裝飾器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
for循環(huán)在Python中的工作原理詳細(xì)
for...in 是Python程序員使用最多的語(yǔ)句,for 循環(huán)用于迭代容器對(duì)象中的元素,這些對(duì)象可以是列表、元組、字典、集合、文件,甚至可以是自定義類(lèi)或者函數(shù),下面小編將舉例說(shuō)明,需要的朋友可以參考下2021-10-10
python實(shí)現(xiàn)倒計(jì)時(shí)的示例
這篇文章主要介紹了python實(shí)現(xiàn)的倒計(jì)時(shí)的示例,需要的朋友可以參考下2014-02-02

