猿问

如果找到数据,则按兄弟姐妹抓取带有 div 类的表

我想抓取一个包含<div class="...">格式元素的 html 表。要刮它,我想我需要使用:


if found driver.find_element_by_xpath contains(footable-row-detail-name)

get value from /following-sibling which is (class="footable-row-detail-value")

这只是一张桌子。我正在抓取的站点有很多表,有些表没有所有数据(这就是“如果找到”的原因)


我想为此使用python 3。我希望我解释得很好。一张表的 HTML 代码:


<div class="footable-row-detail-inner">

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Discipline(s) thérapeutique(s):

    </div>

    <div class="footable-row-detail-value">

        197. Omeopatia, 202. Linfodrenaggio manuale, 205. Massaggio classico, 664. Riflessoterapia generale

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Cognome:

    </div>

    <div class="footable-row-detail-value">

        ABBONDANZIERI Katia

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Via:

    </div>

    <div class="footable-row-detail-value">

        Place du Cirque, 2

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        NPA:

    </div>

    <div class="footable-row-detail-value">

        1204

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Luogo:

    </div>

    <div class="footable-row-detail-value">

        Genève

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Tel / Cellulare:

    </div>

    <div class="footable-row-detail-value">

        022 328 23 44

    </div>

</div>

<div class="footable-row-detail-row">

    <div class="footable-row-detail-name">

        Cellulare:

    </div>

    <div class="footable-row-detail-value">

        079 601 92 75

    </div>

</div>

任何帮助表示赞赏。


慕虎7371278
浏览 168回答 2
2回答

一只名叫tom的猫

使用 python3 的一种解决方案是html.parser模块!有一个简单的示例可以帮助您入门:)
随时随地看视频慕课网APP

相关分类

Python
我要回答