import json
import requests
import pandas as pd
def getId():
idurl = r'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsList'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'}
idlist = []
for page in range(1,20):
page =str(page)
data = {
'on': 'true',
'page': page,
'pageSize': '15',
'productName':'',
'conditionType': '1',
'applyname':'',
'applysn':''
}
responce = requests.post(url=idurl,headers=headers,data=data).json()
print(responce)
print("---------------------------------------")
for dic in responce['list']:
idlist.append(dic['ID'])
return idlist
def getInformation(idlist):
url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?method=getXkzsById'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'}
inforlist = []
for id in idlist:
data = {
'id':id
}
responce = requests.post(url=url,data=data,headers=headers).json()
inforlist.append(responce)
return inforlist
def getDataFrame(idlist):
datall = pd.DataFrame()
for item in idlist:
df = pd.DataFrame.from_dict(item,orient='index').T
datall = datall.append(df)
datall.to_csv('data.csv')
if __name__ == '__main__':
id = getId()
detailinformation = getInformation(id)
getDataFrame(detailinformation)
print("over!!!!")
爬取数据后的具体结果如上图所示。
|