2 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
嘗試 CSS 選擇器div.en-us.stat-value.stat-small:
sneaker_price = soup.select("div.en-us.stat-value.stat-small")[0]
print(sneaker_price.text)
印刷:
€523
注意:如果您獲得驗(yàn)證碼頁面,請(qǐng)嘗試指定更多 HTTP 標(biāo)頭和/或 Cookie。例如:
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Accept-Language': 'en-US,en;q=0.5'
}
cookies = {
'stockx_homepage': "sneakers",
}
soup = BeautifulSoup(requests.get("https://stockx.com/air-jordan-6-retro-travis-scott", headers=headers, cookies=cookies).content,"lxml")
sneaker_price = soup.select("div.en-us.stat-value.stat-small")[0]
print(sneaker_price.text)

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
您可以使用.ask div.en-us.stat-value.stat-small選擇器獲取包含最新要價(jià)的 div。由于有多個(gè)元素,您可以選擇最后一個(gè)元素,例如:
ask_price = soup.select('.ask div.en-us.stat-value.stat-small')[-1]
print(ask_price.text) # $655
添加回答
舉報(bào)