代码展现:
import requests
import os
filename = '法律条文\\'
if not os.path.exists(filename):
os.mkdir(filename)
url = 'https://flk.npc.gov.cn/api/?'
data = {
'type': 'flfg',
'searchType': 'title;vague',
'sortTr': 'f_bbrq_s;desc',
'gbrqStart': '',
'gbrqEnd': '',
'sxrqStart': '',
'sxrqEnd': '',
'sort': 'true',
'page': '1',
'size': '10',
'_': '1704800783355',
}
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
# "https://wb.flk.npc.gov.cn/flfg/WORD/15526420544a4ad18df391c0d8a88a6b.docx"
response = requests.get(url=url,params=data,headers=headers)
data_json = response.json()
for index in data_json['result']['data']:
id = index['id']
title = index['title']
url = 'https://flk.npc.gov.cn/api/detail'
data = {
'id':id
}
new_data = requests.post(url=url,data=data,headers=headers).json()
down_load = 'https://wb.flk.npc.gov.cn'+new_data['result']['body'][0]['path']
name = new_data['result']['body'][0]['path'].split('.')[-1]
content = requests.get(url=down_load,headers=headers).content
with open('法律条文\\'+title+'.'+name,mode='wb') as f:
f.write(content)
print(title,down_load,name)
结果展现:
总结:涉及到了逆向的知识,之后来总结。