Jeril Jeril - 1 month ago 9
Python Question

Python - using the parametes of Flipkart API

I was trying to get the reviews information using the script given in this link. I was able to get for a single page. Is there any way to get it for multiple pages. The following is the code:

import requests

data = {"productId": "MOBEG4XWJG7F9A6Z", # end of url pid=MOBEG4XWJG7F9A6Z
"count": "15",
"ratings": "ALL",
"reviewerType:ALL"
"sortOrder": "MOST_HELPFUL"}

headers = ({"x-user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.92 Safari/537.36 FKUA/website/41/website/Desktop"})
data = requests.get("https://www.flipkart.com/api/3/product/reviews", params=data, headers=headers).json()


I tried changing the parameters as follows:

data = {"productId": "MOBEG4XWJG7F9A6Z", # end of url pid=MOBEG4XWJG7F9A6Z
"count": "15",
"ratings": "ALL",
"reviewerType:ALL"
"sortOrder": "MOST_HELPFUL",
"page": "2"}


But I am getting the same previous reviews. I tried to get the URL path using the following command:

data.request.path_url


and when I tried pasting the obtained URL in the browser its returning an error. Is there any way to find which parameter is used to iterate the page numbers. Kindly help. I am new to Python

Answer

It is the start parameter that controls the current page:

data = {"productId": "MOBEG4XWJG7F9A6Z", # end of url pid=MOBEG4XWJG7F9A6Z
        "count": "15",
        "ratings": "ALL",
        "reviewerType": "ALL"
        "sortOrder": "MOST_HELPFUL",
        "start": "15"}  # page number 2
Comments