我目前正在尝试使用 xpath 查询从 html 站点中提取特定数据,但在提取特定部分时遇到问题。
使用//div[@id='main']/h2
我的 xpath 查询,我可以使用以下内容提取“查看当前”文本:
exampleSite.title = [[element firstChild] content];
但是,我还想引入以下内容:
1. <b>5/9/2013<nbsp><nbsp> 10:58:45 PM</b>
2. <b>6.32</b>
3. <b>5 Total Points</b>
4. <b>3.72</b>
到目前为止,我已经得到了这个://div[@id='main']/table[@class='bodytext']/tr
但这就是我卡住的地方。任何帮助将不胜感激!谢谢!
这是我试图抓取的 html:
<div id="main">
<h2>View Current</h2>
<table width="96%" border="0" cellpadding="4" cellspacing="0" bordercolor="#eeeeee" align="center" height="276" valign="top" class="bodytext">
<tr valign="top" >
<td colspan = 2 height="13" valign="top" align="left" width="54%" class="headerblue" >Balances <br>
</td>
</tr>
<tr valign="top" >
<td colspan = 2 height="13" valign="top" align="left" width="54%" class="text" >Balances
as of: <b>5/9/2013<nbsp><nbsp> 10:58:45 PM</b></td>
</tr>
<tr valign="top" >
<td colspan = 2 height="13" valign="top" align="left" width="46%" class="text" >Account
Number: <b>101010123</b></td>
</tr>
<tr valign="top" >
<td colspan = 2 height="13" valign="top" align="left" width="46%" class="text" ></td>
</tr>
<tr valign="top" >
<td height="13" valign="top" align="left" width="46%" class="text" >Example Card Amount:
<b>6.32</b></td>
<td height="13" valign="top" align="left" width="46%" class="text" ><a href="balance.asp?">View Details</a></td>
</tr>
<tr valign="top" >
<td height="13" valign="top" align="left" width="46%" class="text" >Example Dining Plans:<b>5 Total Points</b>
</td>
<td height="13" valign="top" align="left" width="46%" class="text" ><a href="balance2.asp?">View Details</a></td>
</tr>
<tr valign="top" >
<td height="13" valign="top" align="left" width="46%" class="text" >Credit For Printing:
<b>3.72</b></td>
<td height="13" valign="top" align="left" width="46%" class="text" ><a href="balance1.asp?">View Details</a></td>
</tr>
<td colspan = 2 height="13" valign="top" align="CENTER" class="text">For
questions contact Cashiers at<BR> (000)000-0011 or <a href="mailto:example@example.com">example@example.com</a></td>
</tr>
<tr valign="top">
<td colspan = 2 height="13" valign="top" align="CENTER" class="text" >
<a href="balance1.asp">All Plan Usage for last 90 days is available here</a>
</td>
</tr>
<tr valign="top">
<td colspan = 2 height="13" valign="top" align="CENTER" class="text" >
<a href="balance.asp?pln=Full">All Usage for last 365 days is available here</a>
</td>
</tr>
</table>
</div>