简体   繁体   English

用Nokogiri排除HTML标签

[英]Exclude HTML tag with Nokogiri

I am trying to get all the text in TD tag except what is inside <strong> tags (there might be any number of them). 我正在尝试获取TD标签中的所有文本,除了<strong>标签内的内容(可能有任意数量)。

In this example I want to get: " graavis ● diakriitik ( ) ↝ " and " acute accent`": 在此示例中,我想获取:“ graavis ● diakriitik ( )↝ " and "急性口音`”:

<tr class="level2">
    <td> 
        <strong> grave accent </strong> 
         <strong> (=backquote character) </strong>
         graavis ● diakriitik (`) ↝ 
         <a href="?word=sv82">acute accent</a>
    </td>
</tr>

I'm trying to use the code below, but it doesn't work: 我正在尝试使用下面的代码,但是它不起作用:

desc = page.css('tr td:not(strong)').text

Consider: 考虑:

page.search("strong").remove
page.css(".level2 > td").text.strip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM