【发布时间】:2017-08-23 01:24:33
【问题描述】:
我正在尝试从此 html 代码中抓取一些数据。更准确地说,我想获得所有数字(这里:[401969217, 401969218])。当然html网站更长,数字也更多。
<td class="nw">1. FC Köln</td>
<td class="nw">Hamburger SV</td>
<td class="nw">3 - 7 - 10</td>
<td class="kicktipp-tippabgabe ">
<input name="spieltippForms[401969217].tippAbgegeben" id="spieltippForms_401969217_tippAbgegeben" value="true" type="hidden"/>
<input id="spieltippForms_401969217_heimTipp" name="spieltippForms[401969217].heimTipp" type="tel" value="2" size="2" maxlength="3"/>:
<input id="spieltippForms_401969217_gastTipp" name="spieltippForms[401969217].gastTipp" type="tel" value="2" size="2" maxlength="3"/>
</td>
</tr>
<tr>
<td class="nw kicktipp-time">26.08.17 15:30</td>
<td class="nw">Bayer 04 Leverkusen</td>
<td class="nw">1899 Hoffenheim</td>
<td class="nw">6 - 3 - 10</td>
<td class="kicktipp-tippabgabe ">
<input name="spieltippForms[401969218].tippAbgegeben" id="spieltippForms_401969218_tippAbgegeben" value="true" type="hidden"/>
<input id="spieltippForms_401969218_heimTipp" name="spieltippForms[401969218].heimTipp" type="tel" value="2" size="2" maxlength="3"/>:
<input id="spieltippForms_401969218_gastTipp" name="spieltippForms[401969218].gastTipp" type="tel" value="2" size="2" maxlength="3"/>
</td>
</tr>
<tr>
<td class="nw kicktipp-time"/>
...
我能够通过以下方法刮掉所有团队:
teams = tree.xpath('//td[@class="nw"]/text()')
不幸的是,我不知道如何修改它来解决我的新问题。希望你能帮忙:)
【问题讨论】:
-
看到这些数字在输入和 id 名称中,我看不出 lxml 或 xpath 将如何帮助您仅提取数字本身。
标签: python web-scraping lxml