查找XPath段落(以下 - 兄弟?)

时间:2015-08-04 17:49:33

标签: python selenium xpath

我正在Selenium使用Python 2.7.10,并希望抓住此页面上"Description"标题后的段落:http://etfdb.com/etf/ROBO/

from selenium import webdriver as driver
from selenium.common.exceptions import NoSuchElementException

def scrape(driver, key):
    try:
        find_value = driver.find_element_by_xpath("//span[@class='panel__sub-heading' and . = '%s']/following-sibling::p" % key).text
    except NoSuchElementException:
        print "Not Found"
        return None
    else:
        value = re.search(r"(.+)", find_value).group().encode("utf-8")
        print value
        return value

description = scrape(driver, "Description")

我使用的XPath不正确,因为它没有产生任何结果。在标题"Description"后面找到段落的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

这不是span代码 - 它是h3

//h3[@class='panel__sub-heading' and . = '%s']/following-sibling::p