我正在尝试向网页发送GET HTTP请求,并收到200状态响应。在发出请求时,需要通过链路发送适当的参数。但是,当我使用link
和payload
发送请求时,我总是收到410状态码。
当我在下面的代码中直接使用从开发工具复制的URL时,我得到一个200状态。
请注意,我已经修改了AnchorProdSetId
和ProdSetId
的值,然后才用链接发送有效负载。
在使用带有有效负载的链接发出请求后,如何获得200(检测到时为403)状态?
import json
import requests
complete_url_from_d_tools = 'https://www.mcmaster.com/mv1687879695/WebParts/Content/ContentWebPart.aspx?cntnrIDtxt=ProdPageContent&srchidtxt=5875341805879&cntnrwdth=769&srchrslttxt=screws&GrpUsrInps=[{%22AnchorProdSetId%22:%22-2674186034712253%22,%22AnchorStateIsSet%22:true,%22ClearAllProdSetId%22:-1,%22ClearAllStateIsSet%22:true,%22GrpEID%22:%22%22,%22ProdSetId%22:%22-2674186034712253%22}]&viewporthgt=192&cssAlias=undefined&usedynamicimageswapping=true&conditionalclientlandingpage=true&forcemdmfiltering=true&workstationdata=true&fwdSsToNav=true&fwdSsWpNav=true&fwdCrcWpNav=true&sortRowsOnServer=true&showbroadlandingpagecopy=true&filtSsAttrEarly=true&legImgContainsHash=true&envrmgrcharsetind=3&useEs6=true'
link = 'https://www.mcmaster.com/mv1687538569/WebParts/Content/ContentWebPart.aspx'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9,bn;q=0.8',
'Referer': 'https://www.mcmaster.com/products/screws/',
'X-Requested-With': 'XMLHttpRequest',
}
payload = {
'cntnrIDtxt': 'ProdPageContent',
'srchidtxt': '5875341805879',
'cntnrwdth': '769',
'srchrslttxt': 'screws',
'GrpUsrInps': '[{"AnchorProdSetId":"","AnchorStateIsSet":"true","ClearAllProdSetId":-1,"ClearAllStateIsSet":"true","GrpEID":"","ProdSetId":""}]',
'viewporthgt': '192',
'cssAlias': 'undefined',
'usedynamicimageswapping': 'true',
'conditionalclientlandingpage': 'true',
'forcemdmfiltering': 'true',
'workstationdata': 'true',
'fwdSsToNav': 'true',
'fwdSsWpNav': 'true',
'fwdCrcWpNav': 'true',
'sortRowsOnServer': 'true',
'showbroadlandingpagecopy': 'true',
'filtSsAttrEarly': 'true',
'legImgContainsHash': 'true',
'envrmgrcharsetind': '3',
'useEs6': 'true',
}
payload['GrpUsrInps'] = json.loads(payload['GrpUsrInps'])
payload['GrpUsrInps'][0]['AnchorProdSetId'] = '-2674186034712253'
payload['GrpUsrInps'][0]['ProdSetId'] = '-2674186034712253'
payload['GrpUsrInps'] = json.dumps(payload['GrpUsrInps'])
with requests.Session() as s:
s.headers.update(headers)
# res = s.get(complete_url_from_d_tools)
res = s.get(link,params=payload)
print(res.status_code)
1条答案
按热度按时间dxxyhpgq1#
似乎这个服务器返回brotli压缩响应。要从服务器获取
200
响应,请安装brotli
包:然后:
图纸:
编辑:要获取“内六角螺钉”的内容: