我的目标是提取元素“$37.91”。
但是,由于它的类(突出显示的黄色)在其他地方重复,所以我无法每次都获取这个特定元素。 (有时我会获得其他值)
如何通过以下方式获取元素://div id='snsPrice' & span class='a-size-large a-color-price'。确保精度。
最佳答案
以下应该有效
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"]')
关于python - 在 Selenium 中从父元素中提取特定的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47482291/