如何使用jquery提取子文本数据?(how extract child's text data using jquery?)

编程入门 行业动态 更新时间:2024-10-27 04:32:18
如何使用jquery提取子文本数据?(how extract child's text data using jquery?)

我想从下面给出的html中提取数据'AT401726'

<td class="publicationInfoColumn"> <h4>Publication info:</h4> AT401726<br>2008-08-15 </td>

&我使用JQuery解决了它,下面给出了工作代码

('body').find('.publicationInfoColumn').clone().children().remove().end().text()

是否还有其他更好的技术从上面给出的HTML提取数据? 在我的抓取的html页面中有很多像上面这样的html

i want to extract data 'AT401726' from the html given below

<td class="publicationInfoColumn"> <h4>Publication info:</h4> AT401726<br>2008-08-15 </td>

& i solved it by using JQuery, the working code is given below

('body').find('.publicationInfoColumn').clone().children().remove().end().text()

is there any other better technique to extract data from above given html ? there are many html like above in my crawled html page

最满意答案

您正在寻找h4元素的下一个兄弟元素的内容,请尝试

var text = $.trim($('.publicationInfoColumn h4').prop('nextSibling').nodeValue); console.log(text)

演示: 小提琴

The text you are looking for the the contents of the next sibling element of the h4 element, so try

var text = $.trim($('.publicationInfoColumn h4').prop('nextSibling').nodeValue); console.log(text)

Demo: Fiddle

更多推荐

html,given,电脑培训,计算机培训,IT培训"/> <meta name="description"

本文发布于:2023-08-07 19:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文本   数据   jquery   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!