Sid*_*kan 5 python firefox selenium xpath
我正在尝试从网址https://play.google.com/store/apps/details?id=com.teslacoilsw.launcher&hl=en获取数据并获取以下数据
<meta content="3.99" itemprop="price">
Run Code Online (Sandbox Code Playgroud)
我使用Python中实现的以下代码来获取但失败了.
browser = webdriver.Firefox() # Get local session of firefox
browser.get(sampleURL) # Load page
assert "Google Play" in browser.title
priceValue = browser.find_element_by_xpath("//div[@itemprop='price']")#
print priceValue.text
Run Code Online (Sandbox Code Playgroud)
但它说它无法找到价值价格的xpath.知道为什么吗?
编辑
priceValue = browser.find_element_by_xpath("//meta[@itemprop='price']")
print priceValue.text
Run Code Online (Sandbox Code Playgroud)
我得到空字符串
如果我查看页面来源,例如在Chrome中view-source:https://play.google.com/store/apps/details?id=com.teslacoilsw.launcher&hl=en.我也找不到<div>具有属性@itemprop和值的元素price.
所以你的XPath是完全错误的.还browser.find_element_by_xpath()返回一个元素,并且要提取其属性值@content.然后你应该使用下一个:
priceValue = browser.find_element_by_xpath("//meta[@itemprop='price']")
print priceValue.get_attribute("content")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5483 次 |
| 最近记录: |