1

having trouble with this website to print price, i think i'm close but getting errors.

please help, tx

"
{'statusDetails': {'state': 'FAILURE', 'errorCode': 'SYS-3003', 'correlationid': 'rrt-5636881267628447407-b-gsy1-18837-18822238-1', 'description': 'Invalid key identifier or token'}}
"

code:

import requests

import json

s = requests.Session()

url = 'https://www.bunnings.com.au/ozito-pxc-2-x-18v-cordless-line-trimmer-skin-only_p0167719'

header = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'}


resp = s.get(url,headers=header)

api_url = f'https://api.prod.bunnings.com.au/v1/products/0167719/fulfillment/6400/radius/100000?isToggled=true'

price_resp = s.get(api_url,headers=header).json()

print(price_resp)

#price = price_resp['data']['price']['value']

#print(price)
ggorlen
  • 44,755
  • 7
  • 76
  • 106
d34as5gd
  • 11
  • 1
  • Welcome to SO! "getting errors." -- what errors, specifically? – ggorlen May 26 '21 at 00:39
  • {'statusDetails': {'state': 'FAILURE', 'errorCode': 'SYS-3003', 'correlationid': 'rrt-5636881267628447407-b-gsy1-18837-18822238-1', 'description': 'Invalid key identifier or token'}} – d34as5gd May 26 '21 at 00:41
  • I don't they are receiving errror, just wrong output `{'statusDetails': {'state': 'FAILURE', 'errorCode': 'SYS-3003', 'correlationid': 'rrt-5636881267628447407-b-gsy1-18837-18822238-1', 'description': 'Invalid key identifier or token'}}` – Buddy Bob May 26 '21 at 00:41
  • That seems pretty self-explanatory. You need a token to access their API. The page uses JS to inject the price, so you'd need a webdriver to get it. See https://stackoverflow.com/questions/8049520/web-scraping-javascript-page-with-python# – ggorlen May 26 '21 at 00:41
  • hmm this is beyond my knowledge of acquiring a token to access api. i have successfully webscraped another website that has api with similar code. Well someone else sort of did most of the code, i just reworked the code for this website. – d34as5gd May 26 '21 at 00:44
  • They probably won't give you a token because you're not the front-end of their website. Usually, commercial sites are their own exclusive API clients. The whole point of a token is to prevent random people from accessing it without going through their front-end interface (in other words, exactly what you're trying to do). Other sites sometimes have open APIs that can be scraped, but that's not the case for all sites. – ggorlen May 26 '21 at 00:48
  • ah i see tx 4 reply ggorlen and welcome msg :) – d34as5gd May 26 '21 at 00:52
  • You are looking at JWT - see https://auth0.com/blog/navigating-rs256-and-jwks/ – QHarr May 26 '21 at 02:59

0 Answers0