受害者网站 需要魔法
aHR0cHM6Ly93d3cucmVndWxhdGlvbnMuZ292Lw==
1 获取数据 根据页面的显示 定位到请求的URL
2 找到了headers 有个 X-Api-Key 这个参数 就是一个加密的字段
3 搜一下这个字段是怎么生成的 为什么确定是这个呢 因为找的是生成的 就是response返回中找 前几个都是在header中
4 上代码
import re
import requests
headers = {
'authority': 'www.regulations.gov',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'origin': 'https://www.regulations.gov',
'referer': 'https://www.regulations.gov/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
}
response = requests.get('https://www.regulations.gov/', headers=headers,timeout=20)
#第一次 请求获取x-api-key
api_key= re.search('apiKey%22%3A%22(.*?)%22%2C%22api',response.text).group(1)
print('第一次获取apikey', api_key)
# 把 Apikey 更新到header中
headers.update({'x-api-key':api_key})
params = {
'filter[numberOfDays]': '7',
}
# 再次请求 返回数据
response = requests.get('https://api.regulations.gov/v4/whats-trending', params=params, headers=headers)
print(response.text)
请求结果
{
"data" : [ {
"id" : "BLM-2023-0005-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "BLM",
"commentEndDate" : "2023-09-23T03:59:59Z",
"title" : "Fluid Mineral Leases and Leasing Process"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/BLM-2023-0005-0001"
}
}, {
"id" : "FWS-R2-ES-2022-0162-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "FWS",
"commentEndDate" : "2023-09-02T03:59:59Z",
"title" : "Endangered and Threatened Species: Status for the Dunes Sagebrush Lizard"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/FWS-R2-ES-2022-0162-0001"
}
}, {
"id" : "EEOC-2023-0004-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "EEOC",
"commentEndDate" : "2023-10-11T03:59:59Z",
"title" : "Regulations To Implement the Pregnant Workers Fairness Act"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/EEOC-2023-0004-0001"
}
}, {
"id" : "FWS-HQ-ES-2023-0018-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "FWS",
"commentEndDate" : "2023-08-22T03:59:59Z",
"title" : "Endangered and Threatened Species: Regulations Pertaining to Endangered and Threatened Wildlife and Plants"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/FWS-HQ-ES-2023-0018-0001"
}
}, {
"id" : "FWS-HQ-ES-2021-0104-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "FWS",
"commentEndDate" : "2023-08-22T03:59:59Z",
"title" : "Endangered and Threatened Species: Interagency Cooperation"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/FWS-HQ-ES-2021-0104-0001"
}
}, {
"id" : "FWS-HQ-ES-2021-0107-0001",
"type" : "whats-trending",
"attributes" : {
"documentType" : "Proposed Rule",
"agencyId" : "FWS",
"commentEndDate" : "2023-08-22T03:59:59Z",
"title" : "Endangered and Threatened Species: Listing and Designating Critical Habitat"
},
"links" : {
"self" : "https://api.regulations.gov/v4/whats-trending/FWS-HQ-ES-2021-0107-0001"
}
} ]
}