【发布时间】:2021-07-10 11:01:58
【问题描述】:
如何获取“a-offscreen”类的文本值?
这是要测试的示例工作代码
from selenium import webdriver
driver = webdriver.Chrome(r'c:\chromedriver\chromedriver.exe')
url = 'https://www.amazon.com/s?k=ipad&ref=nb_sb_noss'
driver.get(url)
title = driver.find_element_by_xpath('.//h2/a').text.strip()
# price = driver.find_element_by_xpath('.//*[contains(@class, "a-
offscreen")]').text # does not work
price = driver.find_element_by_xpath('.//*[contains(@class, "a-price-
whole")]').text # work
print('title::', title)
print('price::', price)
我想使用“xpath”获取价格文本值 -> $299.00
这是我正在尝试做的代码。
price = item.find_element_by_xpath('.//*[contains(@class, "a-offscreen")]').text
我无法获得任何价值。
price = item.find_element_by_xpath('.//*[contains(@class, "a-price-whole")]').text
有效(获取价格)
【问题讨论】:
-
@Booboo 抱歉,我添加了我的测试示例代码。
标签: python web-scraping xpath