2012-10-13 54 views
0

我试图刮掉具有锚后一些空间的页面:网络收获 - 删除特殊字符

</a>&nbsp;&nbsp;|&nbsp;&nbsp; 

我似乎无法找到一个方法来指定的文本,我要么触发处理器错误,或者我无法检测到字符串本身。所有事件导致html-to-xml转换失败,因为包含字符时xml格式不正确。所以,我需要删除所有东西之后的所有内容(请注意,在文档中的其他地方有其他地方有div标签或其他东西)。

我的代码:

<xpath expression="/"> 
    <regexp replace="true"> 
      <regexp-pattern>(nbsp;)</regexp-pattern> 
       <regexp-source> 
        <html-to-xml omitcomments="true" advancedxmlescape="true" prunetags="head,script,meta,meta ,p,base,br,link,img,image,input,option,nbsp;"> 
         <http url="http://mysite.org/map/aindex/" method="get" /> 
        </html-to-xml> 
       </regexp-source> 
       <regexp-result> 
        <template></template> 
       </regexp-result> 
     </regexp> 
</xpath> 

我想我的问题是与正则表达式模式。我试过了:

 &nbsp; 
    \& nbsp; (without the space in between -- SO doesn't display that correctly 
    \s+\|\s+

等等。我甚至试图把表达式放在一个CDATA元素中,但是我也无法让它工作。

有什么想法?

+0

这个貌似为什么基于正则表达式的Web刮是有缺陷的另一个很好的例子。我希望你能弄清楚如何使它工作。这是一个有趣而经典的Stack-O答案:http://stackoverflow.com/a/1732454/564406 – David

回答

2

对于&nbsp;在正则表达式模式,你可以尝试使用\u00A0