文章目录
- 前言
- 一、需求
- 二、分析
- 三、测试运行
前言
- 本系列文章来源于真实的需求
- 本系列文章仅供学习参考
- 本系列文章你来提我来做
one:Leave a message at the end of the article
two:Get wechat contact information
一、需求
需求
URL:https://szxt.zjamr.zj.gov.cn/
获取字段:企业名称、统一社会信用代码、公示等级 、公示时间 、有效期至
导出格式:文本文件
二、分析
进入url页面,进入企业公示查询
1、进入按地区展示信息
2、进入具体详细页面
抓包分析请求
请求方式:POST
请求体参数(明文)
a. pageIndex: 1
b. lvl: 3
c. areaIds:
d. name:
e. regNo:
f. year: 0
g. applyType:
h. isRoll: 1
response:{"CurrentPage":1,"TotalPage":377,"TotalCount":3761,"JsonData":"[{\"Fname\":\"上药康德乐(温州)医药有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"913303007625258310\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"ff2b1649-8cf0-4f42-945e-543167a7cc8d,e16911ac-1117-473b-ab12-b710387c16a0\",\"Fyear\":\"2022\"},{\"Fname\":\"浙江新联工程管理咨询有限公司\",\"FapplyType\":\"新申报\",\"FregNo\":\"9133040278569390XC\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"dccbc96a-69cc-468b-9ad6-b784ba9d712b,479dd37f-07c2-4b52-a409-3c6ed7fa3c4a\",\"Fyear\":\"2022\"},{\"Fname\":\"浙江百灵谷生态农林发展有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"91330723586292548K\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"15263231-7b0e-4fd2-91a4-975a7c50df4e,d2dd6440-77ff-4990-abaf-5bfd7a6d50a9\",\"Fyear\":\"2022\"},{\"Fname\":\"传化集团有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"913301092539087031\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"c4af765f-7245-443d-ae54-9a66d462c7dd,5933ba72-7420-4cba-b421-e0abb1a470c5\",\"Fyear\":\"2022\"},{\"Fname\":\"丽水市汽车运输集团股份有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"91331100148861210H\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"29127fde-b0a7-46eb-91be-651d84b21dca,206b55e5-cf89-41b5-98cd-74ea9e3cac07\",\"Fyear\":\"2022\"},{\"Fname\":\"浙江兴业土木建筑工程有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"913310001488861009\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"4ad701c4-e1da-426d-80f4-46ddfecf509b,040a2cf3-f062-4da5-8a5c-b577d8b5e623\",\"Fyear\":\"2022\"},{\"Fname\":\"浙江巴赫厨具有限公司\",\"FapplyType\":\"新申报\",\"FregNo\":\"91330723598547579D\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"6386e5fa-c93d-466d-8796-96f7147afcea,4e3599c0-e011-4cfd-b6fa-c668d4cf6de7\",\"Fyear\":\"2022\"},{\"Fname\":\"杭州顺帆体育发展有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"913301107399475185\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"ef31af1d-daba-46d6-a58b-fc4518d83a16,aa153592-2a85-4b40-bc51-45b466ec1589\",\"Fyear\":\"2022\"},{\"Fname\":\"浙江棉田针织有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"91330782742048994N\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"e98bf84c-cd93-45c0-af03-adb983d4dc12,4efede3f-b146-40b7-8d28-7783d000b21d\",\"Fyear\":\"2022\"},{\"Fname\":\"衢州市枫林机械有限公司\",\"FapplyType\":\"续报\",\"FregNo\":\"91330800727603566N\",\"FstartDate\":\"2022-08-26\",\"FendDate\":\"2024-08-25\",\"Farea\":\"浙江省\",\"Flevel\":\"AAA\",\"Fremark\":\"00e4141a-c325-4a93-9062-60696b32272d,ad360dce-b3fe-457b-a861-83aa925ba3f3\",\"Fyear\":\"2022\"}]"}
构造请求获取数据
import requests
import json
HEADERS = {
'Referer': 'https://szxt.zjamr.zj.gov.cn/publishlvl/list.html?lvl=3',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
}
def get_info(i):
# 请求URL
url = "https://szxt.zjamr.zj.gov.cn/publishlvl/get_data.ashx?method=GetPaging"
params = {
"pageIndex":i,
"lvl": 3,
"areaIds":"",
"name":"",
"regNo":"",
"year":0,
"applyType":"",
"isRoll":0,
}
response = requests.request("POST", url, headers=HEADERS, data=params)
data = json.loads(response.text)
return data
写入文件
def write_file(data):
with open("浙江省企业信用公示名单.txt",mode="a", encoding="utf-8") as f:
# 获取公司的数据
json_data = data['JsonData']
# 将字符串转为List,以便获取值
result = json.loads(json_data)
# 每次获取10个-翻页显示
for item in result:
# 获取公司名称
company_name = item["Fname"]
# 统一社会信用代码
credit_number = item["FregNo"]
# 公示等级
level = item["Flevel"]
# 公示时间
start_time = item["FstartDate"]
# 有效期至
end_time = item["FendDate"]
f.write(f"{company_name},{credit_number},{level},{start_time},{end_time}\n")
print("正在写入文件~~~")
三、测试运行
这里只测试获取100条数据
if __name__ == '__main__':
# 获取100条数据
for i in range(1,11):
# 获取数据
data = get_info(i)
time.sleep(1)
# 写入数据
write_file(data)
print("数据写入完成!")