Feb-06-2022, 12:49 PM
I can't get filtered result using payload, I got generic result. In Postman the result is filtered with same payload.
I think I'm doing something wrong, Here is my code:
I think I'm doing something wrong, Here is my code:
import requests
import json
import pandas as pd
import time
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://xxxxxxx',
'Content-Type': 'application/json;charset=utf-8',
'Origin': 'https://xxxxx',
'Connection': 'keep-alive',
'Cookie': 'ULocation=WW%7Cen; SId=l61eda0332b5f67.36575359_6ef5682a33068fedccdb2eeee5ff26370697b82a; _ga=GA1.2.1306843269.1642962997; _hjSessionUser_1949701=eyJpZCI6IjZiYjUyYjc5LTRkNDAtNTZmNi04OGFhLTlhZDAzYmYzOTNhOSIsImNyZWF0ZWQiOjE2NDI5NjI5OTkxNTMsImV4aXN0aW5nIjp0cnVlfQ==; acceptCookie=1; _gid=GA1.2.115394137.1643138150; _gat=1; _hjSession_1949701=eyJpZCI6ImExNjQ0NWIwLTc3MTgtNDJmNC1iYmViLTg5ZjBmZGY2MzEwYyIsImNyZWF0ZWQiOjE2NDMxMzgxNDk5NTYsImluU2FtcGxlIjpmYWxzZX0=; _hjAbsoluteSessionInProgress=0; _gat_UA-77624103-1=1; ULocation=WW%7Cen',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Cache-Control': 'max-age=0',
'TE': 'trailers'
}
prods = pd.DataFrame([])
for x in range(1,9):
url = f"https://xxxxxxx"
payload = "{\"searchString\":\"\",\"sort\":[\"\",\"\"],\"tmp\":null,\"params\":{\"supplierLocalName\":\"sony\",\"categoryId\":\"1637\"},\"codes\":{\"ean\":[],\"mpn\":[]},\"facetParams\":[{\"name\":\"155712\",\"group\":\"155712\",\"isNum\":false,\"val\":\"wireless\"},{\"name\":\"155712\",\"group\":\"155712\",\"isNum\":false,\"val\":\"wired & wireless\"},{\"name\":\"155712\",\"group\":\"155712\",\"isNum\":false,\"val\":\"true wireless stereo tws\"},{\"name\":\"320952\",\"group\":\"320952\",\"isNum\":false,\"val\":\"headphones\"}],\"p\":{x}}"
r = requests.post(url, headers=headers, data=payload)
data = json.loads(r.text)
prods = prods.append(pd.json_normalize(data['products']), sort=False)
time.sleep(10)
print(f'Getting page {x}', 'waiting..')
prods.to_csv('one.csv')
