爬取国家法律法规数据库法律条文

2024-01-09 21:38:39

代码展现:?

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)

结果展现:?

总结:涉及到了逆向的知识,之后来总结。?

文章来源:https://blog.csdn.net/m0_57265868/article/details/135489188
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。