Python 是否可以从 post 请求中获取请求负载?

Python Is it possible to get request payload from a post request?

我正在尝试通过请求包网络抓取此 URL https://pricempire.com/search 的名称和价格。当我加载站点时,有一个名为 items 的 POST 请求,在请求有效负载中有一个名为 captchaToken 的属性,基本上我想捕获此属性并使用它来创建对其他页面的请求。我一直在使用 Selenium 来抓取名称和价格,但加载每个页面需要 20 秒,速度非常慢。所以我的目标是捕获请求有效负载中的 captchaToken,如下所示:

json_data = {
    'page': 1,
    'priceMin': 0,
    'orderBy': 'price_desc',
    'captchaToken': 'aaabbbcccxxxzzzyyy',
    'priceMax': 200000,
    'collections': [],
    'weaponIds': [],
    'wears': [],
    'priceProvider': 'buff163',
}

加快网站的抓取速度。但我不知道这是否可能,根据我的研究,我不知道这个问题的答案。

在post请求中,你必须添加服务器作为payload发送的数据作为json响应,captcha Token也是有效负载数据的一部分.这是一个示例,如何从 api 调用 json 响应中提取数据(名称、价格)作为 post 方法。

import requests
import json
URL = "https://public-api.pricempire.com/api/search/items"

body= {"page":1,"priceMin":0,"orderBy":"price_desc","captchaToken":"03AGdBq271Msp7k_yCTzgNsheZ1yRqLWykDZL17tIK9_YAVo2uZGc3cLH0sNhuZOFsnymBSAbuzRRo2w_Cy6kEEMxaRxgkuZUlXFcDzRPWgYs-Hy-fV5SpxLjU8rACYW3KwZ8y-js1Dye8weAdMfZSPeEBgQ9YP3zdbaPrUOJAHHmjkpqTxH7vPW-Cd2PXHtZf5NlgVkxCBUKIESAyMJ6FyKdNz_WxYdIJvK4uQa6nBdHxMlmQZx6rUgus65NxZkwTaY3BO36ju68WNerv-fQBqFdIz_6jUPfav41DYFiApv9O-MbdASQqpS-ma1TG76mQ82OQdzkqqvpZtAksBGa836HzsxfaOecgbZ2YbswAHr1dXxl919DbRnZum4Wr-UUZMQ66j8Iy5UA_g4B3Ir7IxTf50KhTOrNHtqIIYuBR4Vfz6scc5c7XqATeqMoMvL-06wbBWVATSI44","priceMax":200000,"collections":[],"weaponIds":[],"wears":[],"priceProvider":"buff163"}

headers={
    'content-type': 'application/json',
    'User-Agent':'mozila/5.0/'
    }
jsonData=requests.post(URL,headers=headers,data=json.dumps(body)).json()


for item in jsonData['items']:
    name= item['name'].replace('★','').replace('|','').strip()
    price=item['price']['price']
    print(name)
    print(price)

输出:

Souvenir AWP  Dragon Lore (Minimal Wear)
100000000
Sticker  iBUYPOWER (Holo)  Katowice 2014    
49999900
Sticker  Titan (Holo)  Katowice 2014        
49999800
Souvenir AWP  Dragon Lore (Field-Tested)    
36388800
Sticker  Reason Gaming (Holo)  Katowice 2014
30000000
Souvenir AWP  Dragon Lore (Battle-Scarred)  
23618000
Sport Gloves  Pandora's Box (Factory New)
22000000
Sticker  Team LDLC.com (Holo)  Katowice 2014
16750000
StatTrak™ Ursus Knife  Crimson Web (Factory New)
15000000
StatTrak™ Talon Knife  Crimson Web (Factory New)
15000000
StatTrak™ Nomad Knife  Safari Mesh (Battle-Scarred)
15000000
Survival Knife  Crimson Web (Factory New)
14999999
StatTrak™ Stiletto Knife  Slaughter (Field-Tested)
14888800
Sport Gloves  Vice (Factory New)
13400000
Sticker  Vox Eminor (Holo)  Katowice 2014
13000000
Sticker  Team Dignitas (Holo)  Katowice 2014
11886000
StatTrak™ M9 Bayonet  Case Hardened (Factory New)
10999900
StatTrak™ Paracord Knife  Crimson Web (Factory New)
10000000
StatTrak™ Ursus Knife  Fade (Minimal Wear)
10000000
Sport Gloves  Slingshot (Factory New)
10000000