문제

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

도움이 되었습니까?

해결책

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

다른 팁

Use:

$('td.publicationInfoColumn').text();//for text

or

$('td.publicationInfoColumn').html();//for html

You're not supposed to be able to target specific text nodes like that. The best you can probably do is:

$('.publicationInfoColumn').html().match(/\b.*(?=<br>)/)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top