0

我在 R 中使用 XML 包来抓取表。但是,刮桌子后,我在结果中得到了一些奇怪的字符。这是我获取表格的脚本:

TUrlhtml <- htmlParse(htmlfile)
TUrlTable <- xpathSApply(TUrlhtml, 
                          "//table[@class='results_table']/tr/td",
                          xmlValue)

这是我得到的结果:

[1] ""                                  "\xc2\xa02 HK"                      "Clp Holdings Limited\xc2\xa0"     "\xc2ec-00\xc2\xa0"             "66.60\xc2\xa0"        
[6] "\xc2\xa026-Feb-12\xc2\xa0"      "\xc2\xa0"                          ""                                  "\xc2\xa03 HK"                      "Hong Kong & China Gas Co\xc2\xa0"
[11] "\xc2un-03\xc2\xa0"             "21.40\xc2\xa0"                   "\xc2\xa019-Mar-12\xc2\xa0"      "\xc2\xa0"   

但是,当我使用 Internet Explorer 或 firefox 查看 html 文件时,html 文件本身绝对没有问题。我应该如何解决?非常感谢您的宝贵建议!这是我的html文件:

<table id="main_table" class="results_table" bgcolor="white" cellspacing="0" cellpadding="0" border="0"><thead style="background-color: white;"><tr class="top_row" style="padding-bottom: 3px; color: #0033cc"><th style="vertical-align:bottom">
<!--si--><link rel="stylesheet" href="/classes/user_interface/vertical_menu_panel@12.41.004@.css" type="text/css" >      <div class="yui-skin-sam">
      <div class="vertical_menu_panel" style="display:none">
        <div class="hd" style="display:none"></div>
        <div class="bd">
          <ul> <li class="primary_sort_ascending"><img class="primary_sort_ascending" src="/images/primary_sort_ascending.gif"/>&nbsp;Sort Asc<span class="action" style="display:none">primary_sort_ascending</span></li> <li class="primary_sort_descending"><img class="primary_sort_descending" src="/images/primary_sort_descending.gif"/>&nbsp;Sort Desc<span class="action" style="display:none">primary_sort_descending</span></li> <li class="add_column"><img class="add_column" src="/images/add_column_left.gif"/>&nbsp;Add Column Here<span class="action" style="display:none">add_column</span></li> <li class="remove_column"><img class="remove_column" src="/images/subtract_small.gif"/>&nbsp;Remove Column<span class="action" style="display:none">remove_column</span></li>          </ul>
        </div>
        <div class="ft" style="display:none"></div>
      </div>
      </div>
<input style="" type="checkbox" id="master_check_box" title="Select All">
</th>      <td width="" valign="middle" align="center" nowrap><img alt="" border=0 src="/images/shim.gif" width="1" height="1"></td>
  <td width="75" valign="bottom" nowrap class="txtScreen column_header">&nbsp;<span style="text-decoration: underline;"><br><br><br>Ticker</span><IMG alt="" border="0" height="8" src="/images/b_sort_flat_rv.gif" width="10">&nbsp;  <img class="menu_icon" style="position:absolute; vertical-align:bottom; display:none" border="0" src="/images/arrow_down_button.gif"/>   <span class="attributes" style="display: none"><span class="column_id">0</span><span class="display_name">Ticker</span></span></td>
                          <td valign="bottom" align="left" nowrap class="txtScreen column_header  "><span href="#" onclick="return false"><span style="text-decoration: underline;">Company Name</span>                           <img class="menu_icon" style="position:absolute; vertical-align:bottom; display:none" border="0" src="/images/arrow_down_button.gif"/> <span class="attributes" style="display: none"><span class="column_id">2886069004</span><span class="display_name">Company Name</span></span></td>
                          <td valign="bottom" align="center" nowrap class="txtScreen column_header  "><span href="#" onclick="return false"><span style="text-decoration: underline;">Last<br>Quarter<br>Date</span>                           <img class="menu_icon" style="position:absolute; vertical-align:bottom; display:none" border="0" src="/images/arrow_down_button.gif"/> <span class="attributes" style="display: none"><span class="column_id">2886070004</span><span class="display_name">Last Quarter Date</span></span></td>
                          <td valign="bottom" align="center" nowrap class="txtScreen column_header  "><span href="#" onclick="return false"><span style="text-decoration: underline;">Price</span>                           <img class="menu_icon" style="position:absolute; vertical-align:bottom; display:none" border="0" src="/images/arrow_down_button.gif"/> <span class="attributes" style="display: none"><span class="column_id">2886071004</span><span class="display_name">Price</span></span></td>
                          <td valign="bottom" align="center" nowrap class="txtScreen column_header  "><span href="#" onclick="return false"><span style="text-decoration: underline;">Date of<br>Last Report</span>                           <img class="menu_icon" style="position:absolute; vertical-align:bottom; display:none" border="0" src="/images/arrow_down_button.gif"/> <span class="attributes" style="display: none"><span class="column_id">2886072004</span><span class="display_name">Date of Last Report</span></span></td>
        <td width="100%" class="txtScreen">&nbsp;</td></tr>
      </thead>
        <tr bgcolor="#eeeeee">          <th style="height: 15px">
          <input class="select_cb" type="checkbox" style="height: 13px">
          <span class="attributes" style="display: none"><span class="security_id">28411</span></span>
          </th>
                <td valign="middle" align="center"></td>



        <td align="left" nowrap class="txtScreen">&nbsp;<a href="/stocks/stocks.phtml?security_id=28411&ticker=2+HK" target="_parent" >2 HK</a></td>
        <td align="left" nowrap class="txtScreen" title="Company Name">Clp Holdings Limited&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Last&#13;Quarter&#13;Date">&nbsp;&nbsp;Dec-00&nbsp;&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Price">66.60&nbsp;&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Date of&#13;Last Report">&nbsp;&nbsp;26-Feb-12&nbsp;&nbsp;&nbsp;</td>
<td bgcolor="#ffffff">&nbsp;</td> </tr>
        <tr bgcolor="#ffffff">          <th style="height: 15px">
          <input class="select_cb" type="checkbox" style="height: 13px">
          <span class="attributes" style="display: none"><span class="security_id">48569</span></span>
          </th>
                <td valign="middle" align="center"></td>



        <td align="left" nowrap class="txtScreen">&nbsp;<a href="/stocks/stocks.phtml?security_id=48569&ticker=3+HK" target="_parent" >3 HK</a></td>
        <td align="left" nowrap class="txtScreen" title="Company Name">Hong Kong & China Gas Co&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Last&#13;Quarter&#13;Date">&nbsp;&nbsp;Jun-03&nbsp;&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Price">21.40&nbsp;&nbsp;&nbsp;</td>
        <td align="right" nowrap class="txtScreen" title="Date of&#13;Last Report">&nbsp;&nbsp;19-Mar-12&nbsp;&nbsp;&nbsp;</td>
<td bgcolor="#ffffff">&nbsp;</td> </tr>
</table>
4

1 回答 1

2

它是由不断裂引起的   空间。

那就是unicode字符0xA0,在UTF-8中是\xC2\xA0。

我不知道为什么它还在中间插入 EE7B。

于 2013-02-13T00:05:13.983 回答