I’ve created a script in Python using the requests module to fetch the JSON response comprising tabular content visible on this website. However, the script always comes up with a 403 status code.
import requests
link = 'https://www.psacard.com/auctionprices/GetItemLots'
payload = {
'draw': '1',
'start': '0',
'length': '25',
'specID': '184637',
'selectedGradeValue': '',
}
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',
'X-Requested-With': 'XMLHttpRequest',
'Host': 'www.psacard.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'en-US,en;q=0.9',
'Origin': 'https://www.psacard.com',
'Referer': 'https://www.psacard.com/auctionprices/baseball-cards/1963-topps/1963-rookie-stars/values/184637',
}
with requests.Session() as s:
s.headers.update(headers)
res = s.post(link,data=payload)
print(res.status_code)
print(res.json())
How can I produce the JSON response using the script above?