通过抓包分析我们可以发现该页面的数据是动态传输的,也就是通过ajax获取的数据,因此我们可以通过浏览器的控制台获取ajax请求和参数。详情页面也是同样的道理。
#药监管理局
url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList'
header = {
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
id_list = []
name_list = []
id_name = {
}
for page in range(1,2):
data = {
'on': 'true',
'page': page,
'pageSize': 15,
'productName':'',
'conditionType': 1,
'applyname':''
}
response = requests.post(url=url, headers=header,data=data)
page_json = response.json()
json_id = page_json['list']
for dic in json_id:
id_list.append(dic['ID'])
name_list.append(dic['EPS_NAME'])
id_name[dic['EPS_NAME']] = dic['ID']
#详情数据获取
url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById'
header = {
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
for name in name_list:
print(name)
name = input("请输入要查询的公司:")
getId = id_name[name]
print(getId)
data = {
'id':getId
}
response = requests.post(url=url, headers=header,data=data)
print(response.json())