Spaces:
Paused
Paused
log post request
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ import requests
|
|
| 38 |
|
| 39 |
|
| 40 |
def request_product_id(shop_domain, product_key):
|
| 41 |
-
|
| 42 |
payload = {
|
| 43 |
"operationName": "PDPGetLayoutQuery",
|
| 44 |
"variables": {
|
|
@@ -86,9 +86,21 @@ def request_product_id(shop_domain, product_key):
|
|
| 86 |
"X-TKPD-AKAMAI": "pdpGetLayout",
|
| 87 |
}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
def request_product_review(product_id, page=1, limit=20):
|
|
@@ -161,9 +173,17 @@ def request_product_review(product_id, page=1, limit=20):
|
|
| 161 |
"X-TKPD-AKAMAI": "productReviewList",
|
| 162 |
}
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
def scrape(product_id, max_reviews=LIMIT):
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def request_product_id(shop_domain, product_key):
|
| 41 |
+
ENDPOINT = "https://gql.tokopedia.com/graphql/PDPGetLayoutQuery"
|
| 42 |
payload = {
|
| 43 |
"operationName": "PDPGetLayoutQuery",
|
| 44 |
"variables": {
|
|
|
|
| 86 |
"X-TKPD-AKAMAI": "pdpGetLayout",
|
| 87 |
}
|
| 88 |
|
| 89 |
+
try:
|
| 90 |
+
response = requests.request(
|
| 91 |
+
method="POST",
|
| 92 |
+
url=ENDPOINT,
|
| 93 |
+
json=payload,
|
| 94 |
+
headers=headers,
|
| 95 |
+
timeout=30
|
| 96 |
+
)
|
| 97 |
+
response.raise_for_status() # Raise an exception for non-2xx status codes
|
| 98 |
+
logger.info(f"Request successful. Status code: {response.status_code}")
|
| 99 |
+
# Process the response data
|
| 100 |
+
except requests.exceptions.RequestException as e:
|
| 101 |
+
logger.error(f"Request failed: {e}")
|
| 102 |
+
else:
|
| 103 |
+
return response
|
| 104 |
|
| 105 |
|
| 106 |
def request_product_review(product_id, page=1, limit=20):
|
|
|
|
| 173 |
"X-TKPD-AKAMAI": "productReviewList",
|
| 174 |
}
|
| 175 |
|
| 176 |
+
try:
|
| 177 |
+
response = requests.request(
|
| 178 |
+
method="POST", url=ENDPOINT, json=payload, headers=headers, timeout=30
|
| 179 |
+
)
|
| 180 |
+
response.raise_for_status() # Raise an exception for non-2xx status codes
|
| 181 |
+
logger.info(f"Request successful. Status code: {response.status_code}")
|
| 182 |
+
# Process the response data
|
| 183 |
+
except requests.exceptions.RequestException as e:
|
| 184 |
+
logger.error(f"Request failed: {e}")
|
| 185 |
+
else:
|
| 186 |
+
return response
|
| 187 |
|
| 188 |
|
| 189 |
def scrape(product_id, max_reviews=LIMIT):
|