我试图从这个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
的方法是使用这样的代码。你知道吗我不知道在
id
的值中会发现什么样的可变性,所以说如何处理这些值并不容易。但可能很简单在xpath表达式中,您不需要
'//td[@class="nw"]/text()'
,因为这将获取以class="nw"
作为属性的标记之间的值。相反,基于您提供的html和所需的输出,您应该尝试获取input
标记的name
属性并解析该值。你知道吗相关问题 更多 >
编程相关推荐