下面是我將解析的html
的片段。它存儲在js
變量中。從包含html的js變量解析數據
<tr class='preview'>
<td class='statistics show' title='Show latest match stats'>
<button class="js-hide">Show</button>
</td>
<td class='match-details'>
<p>
<span class='team-home teams'>
<a href='#'>Leicester</a>
</span>
<span class='versus'>
<abbr title='Versus'> V </abbr>
</span>
<span class='team-away teams'>
<a href='#'>Crystal Palace</a>
</span>
</p>
</td>
<td class='kickoff'>
15:00
</td>
<td class='status'></td>
</tr>
<tr class='preview'>
<td class='statistics show' title='Show latest match stats'>
<button class="js-hide">Show</button>
</td>
<td class='match-details'>
<p>
<span class='team-home teams'>
<a href='#'>Liverpool</a>
</span>
<span class='versus'>
<abbr title='Versus'> V </abbr>
</span>
<span class='team-away teams'>
<a href='#'>Spurs</a>
</span>
</p>
</td>
<td class='kickoff'>
15:00
</td>
<td class='status'></td>
</tr>
結果..
Leicester vs. Crystal Palace
Liverpool vs. Spurs
我感興趣的home
和away
球隊的名字。可以輕鬆地在每個之間添加vs.
。
任何人都可以建議,如果有一個簡單的解決方案來解析這string
? RegEx
是唯一的方法嗎?