我想找到bdi標簽中的值 280 。我嘗試使用該findAll方法對其進行跟蹤,但它在另一個bdi標簽中為我提供了另一個現有編號
HTML 格式

代碼
def function():
price=soup.findAll('bdi')[4].get_text()
return price
輸出
199
340
uj5u.com熱心網友回復:
首先找到包含該
bdi價格標簽的主要 HTML 標簽,并基于我find_all在div標簽上使用的方法和索引 0 上的資料存在,以便我們可以根據它獲取!
import requests
from bs4 import BeautifulSoup
response = requests.get('https://www.maroc4gaming.net/index.php/produit/erxung-j5-blue/')
soup = BeautifulSoup(response.text,'html.parser')
在代碼中,我在替代條件中使用了串列理解和 for 回圈
main_data=soup.find_all("div",class_="price-wrapper")[0].find_all("span",class_="woocommerce-Price-amount amount")
price_len=len(main_data)
if price_len==1:
price=[i.text.split("\xa0")[0] for i in main_data]
print("Latest Price" " " price[0])
else:
price=[i.text.split("\xa0")[0] for i in main_data]
print("Latest Price" " " price[1])
輸出:
'280.0'
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/344495.html
