从硒的父元素中提取特定的子元素

2024-04-25 13:02:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是提取元素'$37.91'。在

但是,由于它的类(突出显示的黄色)在其他地方重复,所以我不能每次都获得这个特定的元素。(有时我会得到其他值)

如何通过类似于://div id='snsPrice'&span class='a-size-large a-color-price'之类的内容获取元素。以确保精度。在

enter image description here


Tags: divid元素内容目标size地方price
2条回答

试试这个xpath 串成本=驱动程序.findElement(按.xpath(//span[包含(@class,'total-price-value')]).getText()

以下应该行得通

driver.find_element_by_css_selector('#snsPrice > .snsPriceBlock > .a-color-price')

driver.find_element_by_xpath('//*[@id="snsPrice"]/div/span[@class="a-size-large a-color-price"]')

相关问题 更多 >