Javascript 如何提取child';使用jquery创建文本数据?
我想从下面给出的html中提取数据“AT401726”Javascript 如何提取child';使用jquery创建文本数据?,javascript,jquery,html,web-crawler,phpquery,Javascript,Jquery,Html,Web Crawler,Phpquery,我想从下面给出的html中提取数据“AT401726” <td class="publicationInfoColumn"> <h4>Publication info:</h4> AT401726<br>2008-08-15 </td> ('body').find('.publicationInfoColumn').clone().children().remove().end().text() 有没有其他更好的技术从上述h
<td class="publicationInfoColumn">
<h4>Publication info:</h4>
AT401726<br>2008-08-15
</td>
('body').find('.publicationInfoColumn').clone().children().remove().end().text()
有没有其他更好的技术从上述html中提取数据?在我的已爬网html页面中有许多类似于上面的html使用:
$('td.publicationInfoColumn').text();//for text
或
您要查找的文本包含h4元素的下一个同级元素的内容,请尝试
var text = $.trim($('.publicationInfoColumn h4').prop('nextSibling').nodeValue);
console.log(text)
演示:您不应该以这样的特定文本节点为目标。您可能能做的最好的事情是:
$('.publicationInfoColumn').html().match(/\b.*(?=<br>)/)
$('.publicationInfoColumn').html().match(/\b.*(=
)/)
html将包含标题,但OVE代码将提供>>发布信息:AT4017262008-08-15,但我只想要AT401726
$('.publicationInfoColumn').html().match(/\b.*(?=<br>)/)