【发布时间】:2023-03-16 16:13:01
【问题描述】:
我试图从电子商务网站获取数据,并按类别找到了他们产品信息的 API。我把这些放在我的 python 控制台中:
import requests
response = requests.post('https://gql.tokopedia.com/', data={"operationName":"SearchProductQuery","variables":{"params":"&ob=23&identifier=dapur_aksesoris-dapur_alat-pemotong-serbaguna&sc=3470&user_id=110487876&rows=60&start=1&source=directory&device=desktop&page=1&related=true&st=product&safe_search=false","adParams":"&page=1&dep_id=3470&ob=23&ep=product&item=15&src=directory&device=desktop&user_id=110487876&minimum_item=15&start=1&no_autofill_range=5-14"},"query":"query SearchProductQuery($params: String, $adParams: String) {\n CategoryProducts: searchProduct(params: $params) {\n count\n data: products {\n id\n url\n imageUrl: image_url\n imageUrlLarge: image_url_700\n catId: category_id\n gaKey: ga_key\n countReview: count_review\n discountPercentage: discount_percentage\n preorder: is_preorder\n name\n price\n original_price\n rating\n wishlist\n labels {\n title\n color\n __typename\n }\n badges {\n imageUrl: image_url\n show\n __typename\n }\n shop {\n id\n url\n name\n goldmerchant: is_power_badge\n official: is_official\n reputation\n clover\n location\n __typename\n }\n labelGroups: label_groups {\n position\n title\n type\n __typename\n }\n __typename\n }\n __typename\n }\n displayAdsV3(displayParams: $adParams) {\n data {\n id\n ad_ref_key\n redirect\n sticker_id\n sticker_image\n productWishListUrl: product_wishlist_url\n clickTrackUrl: product_click_url\n shop_click_url\n product {\n id\n name\n wishlist\n image {\n imageUrl: s_ecs\n trackerImageUrl: s_url\n __typename\n }\n url: uri\n relative_uri\n price: price_format\n campaign {\n original_price\n discountPercentage: discount_percentage\n __typename\n }\n wholeSalePrice: wholesale_price {\n quantityMin: quantity_min_format\n quantityMax: quantity_max_format\n price: price_format\n __typename\n }\n count_talk_format\n countReview: count_review_format\n category {\n id\n __typename\n }\n preorder: product_preorder\n product_wholesale\n free_return\n isNewProduct: product_new_label\n cashback: product_cashback_rate\n rating: product_rating\n top_label\n bottomLabel: bottom_label\n __typename\n }\n shop {\n image_product {\n image_url\n __typename\n }\n id\n name\n domain\n location\n city\n tagline\n goldmerchant: gold_shop\n gold_shop_badge\n official: shop_is_official\n lucky_shop\n uri\n owner_id\n is_owner\n badges {\n title\n image_url\n show\n __typename\n }\n __typename\n }\n applinks\n __typename\n }\n template {\n isAd: is_ad\n __typename\n }\n __typename\n }\n}\n"})
print(response)
我开始的网站是https://www.tokopedia.com/p/dapur/aksesoris-dapur/alat-pemotong-serbaguna。供您参考。
【问题讨论】:
标签: python http python-requests web-crawler