python - 在 Selenium 中从父元素中提取特定的子元素

标签 python selenium web-scraping

我的目标是提取元素“$37.91”。

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

如何通过以下方式获取元素://div id='snsPrice' & span class='a-size-large a-color-price'。确保精度。

enter image description here

最佳答案

以下应该有效

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/

相关文章:

python - 实体引用和 lxml

Python:用索引展平嵌套列表

javascript - Selenium (C#),使用 JavaScript 查找元素失败

python - 合并备用索引组合处的 n 元组列表

java - 使 TestNG 测试依赖于成功完成的测试

python - 为需要身份验证的网页使用 selenium 进行 Scrapy

java - 使用 jsoup 解析表格

xml - 在 XML 树中搜索特定文本并在下一个节点中提取文本

node.js - 在 NodeJS 上使用 Nightmare (PhantomJS) 抓取动态网页需要的时间太长。我怎样才能使这个过程更快?

类内嵌套函数内的 Python 作用域?