我正试图通过请求包在网上刮取这个网址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',
}
以加快网站的抓取速度。但我不知道这是否可能,从我的研究中,我不知道这个问题的答案。
发布于 2022-04-19 08:34:02
在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
https://stackoverflow.com/questions/71928044
复制相似问题