我们如何从具有相同类名的多个div标签中抓取和获取数据?

时间:2015-06-24 04:36:57

标签: ruby selenium-webdriver

<!DOCTYPE html>
<html>
    <head>
        <title>Sample Crawl</title>
    </head>
    <body>
        <div class="software">
            <h3>Company 1</h3>
            <p>Google</p>
        </div>
        <div class="software">
            <h3>Company 2</h3>
            <p>Facebook</p>
        </div>
        <div class="software">
            <h3>Company 3</h3>
            <p>Github</p>
        </div>
        <div class="software">
            <h3>Company 4</h3>
            <p>Yahoo</p>
        </div>
    </body>
</html>

下面我编写了获取单个div标签内容的代码

    driver.find_element(:xpath => "//div[@class='software']/h3").text
    driver.find_element(:xpath => "//div[@class='software']/p").text

但是我无法遍历具有相同class =“software”的每个div标签

0 个答案:

没有答案