我正试图从URL https://play.google.com/store/apps/details?id=com.teslacoilsw.launcher&hl=en获取数据并获取下面的数据
<meta content="3.99" itemprop="price">
我使用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
但它说它找不到价值价格的xpath。知道为什么吗?
编辑
priceValue = browser.find_element_by_xpath("//meta[@itemprop='price']")
print priceValue.text
我得到空字符串
如果我查看页面源代码,例如Chrome
view-source:https://play.google.com/store/apps/details?id=com.teslacoilsw.launcher&hl=en
。我也找不到具有属性@itemprop
和值price
的<div>
元素。所以您的XPath是完全错误的。同时
browser.find_element_by_xpath()
返回一个元素,您需要提取@content
的属性值。然后您应该使用next:相关问题 更多 >
编程相关推荐