当我导航到This WEBPAGE并输入这个搜索地址:New York City, New York, USA
时,我可以在网页上看到搜索结果.我在下面粘贴的脚本可以产生相同的结果.
然而,现在我希望使用Filter results
按钮来更改选项中的一些内容,例如SERVICES
中的Printing your mailpiece
、DISTANCE
中的within 50 miles
和SORT
中的By distance
,然后使用Apply Filters
按钮来过滤结果,这是我不能做的.
import time
import requests
url = 'https://printerdirectory.usps.com/listing/api/vendors'
link = 'https://gis.usps.com/arcgis/rest/services/locators/EDDM_Composite/GeocodeServer/suggest'
params = {
'text': 'New York City, New York, USA',
'f': 'json'
}
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',
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Origin': 'https://printerdirectory.usps.com',
'Referer': 'https://printerdirectory.usps.com/'
}
result_params = {
'noCache': ''
}
result_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',
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Host': 'printerdirectory.usps.com',
'Referer': 'https://printerdirectory.usps.com/listing/',
'Location': '',
'Key': '',
'Type': 'key',
'Lazyupdate': '[object Object]'
}
with requests.Session() as s:
s.headers.update(headers)
res = s.get(link,params=params)
result_headers['Location'] = res.json()['suggestions'][0]['text']
result_headers['Key'] = res.json()['suggestions'][0]['magicKey']
s.headers.update(result_headers)
unixtime = int(time.time()*1000)
result_params['noCache'] = unixtime
resp = s.get(url,params=result_params)
print(resp.json()['vendors'])
我怎样才能通过请求模块使用Apply Filters
按钮?