如何使用driver.find_element_by_xpath连续获取所有信息

时间:2018-03-01 08:29:52

标签: python python-3.x selenium-webdriver

我试图提取所有这些信息,但获得的结果除了第一个块:   driver.find_elements_by_xpath(“// article [contains(@class,'dual block block')]”) 但我需要所有人,我该怎么办,谢谢你。

binary = FirefoxBinary('/usr/bin/firefox')
    driver = webdriver.Firefox(firefox_binary=binary, executable_path = r'/home/twitter/geckodriver')
    driver.get('https://www...')
    d = driver.find_elements_by_xpath("//article[contains(@class, 'bi-bloc blocs')]")

    for article in d :
            name = article.find_element_by_xpath("//a[contains(@class, 'denomination-links')]")
            if name is not None :
                print ("####1#####")
                print (name.get_attribute("title"))
            logo = article.find_element_by_xpath("//img[contains(@src, 'data:image/png;base64')]")
            if logo is not None :
                print ("####2#####")
                print (logo.get_attribute("data-pjlazyload").replace('{"effect":"fadeIn", "src":"',"http:").replace('?w=140&h=140&crop=1"}',''))
            adresse = article.find_element_by_xpath("//a[contains(@title, 'Voir le plan')]")
            if adresse is not None :
                print ("####3#####")
                print (adresse.text)
            desc = article.find_element_by_xpath("//a[contains(@class, 'activites pj-lb pj-link')]")
            if desc is not None :
                print ("####4#####")
                print (desc.text)
            prest = article.find_element_by_xpath("//p[contains(@class, 'cviv cris')]")
            if prest is not None :
                print ("####5#####")
                print (prest.text)
            num = article.find_element_by_xpath("//strong[contains(@class, 'num')]")
            if num is not None :
                print ("####6#####")
                print (num.get_attribute("title"))
            time = article.find_element_by_xpath("//span[contains(@class, 'value')]")
            if time is not None :
                print ("####7#####")
                print (time.text)

0 个答案:

没有答案