Spaces:
Sleeping
Sleeping
File size: 4,016 Bytes
cd4d249 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
import requests
ENDPOINT = "https://gql.tokopedia.com/graphql/productReviewList"
def request_product_id(shop_domain, product_key):
endpoint = "https://gql.tokopedia.com/graphql/PDPGetLayoutQuery"
payload = {
"operationName": "PDPGetLayoutQuery",
"variables": {
"shopDomain": f"{shop_domain}",
"productKey": f"{product_key}",
"apiVersion": 1,
},
"query": """fragment ProductVariant on pdpDataProductVariant {
errorCode
parentID
defaultChild
children {
productID
}
__typename
}
query PDPGetLayoutQuery($shopDomain: String, $productKey: String, $layoutID: String, $apiVersion: Float, $userLocation: pdpUserLocation, $extParam: String, $tokonow: pdpTokoNow, $deviceID: String) {
pdpGetLayout(shopDomain: $shopDomain, productKey: $productKey, layoutID: $layoutID, apiVersion: $apiVersion, userLocation: $userLocation, extParam: $extParam, tokonow: $tokonow, deviceID: $deviceID) {
requestID
name
pdpSession
basicInfo {
id: productID
}
components {
name
type
position
data {
...ProductVariant
__typename
}
__typename
}
__typename
}
}
""",
}
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Referer": "https://www.tokopedia.com",
"X-TKPD-AKAMAI": "pdpGetLayout",
}
return requests.request(method="POST", url=endpoint, json=payload, headers=headers)
def request_product_review(product_id, page=1, limit=20):
payload = {
"operationName": "productReviewList",
"variables": {
"productID": f"{product_id}",
"page": page,
"limit": limit,
"sortBy": "",
"filterBy": "",
},
"query": """query productReviewList($productID: String!, $page: Int!, $limit: Int!, $sortBy: String, $filterBy: String) {
productrevGetProductReviewList(productID: $productID, page: $page, limit: $limit, sortBy: $sortBy, filterBy: $filterBy) {
productID
list {
id: feedbackID
variantName
message
productRating
reviewCreateTime
reviewCreateTimestamp
isReportable
isAnonymous
reviewResponse {
message
createTime
__typename
}
user {
userID
fullName
image
url
__typename
}
likeDislike {
totalLike
likeStatus
__typename
}
stats {
key
formatted
count
__typename
}
badRatingReasonFmt
__typename
}
shop {
shopID
name
url
image
__typename
}
hasNext
totalReviews
__typename
}
}
""",
}
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Referer": "https://www.tokopedia.com",
"X-TKPD-AKAMAI": "productReviewList",
}
return requests.request(method="POST", url=ENDPOINT, json=payload, headers=headers) |