Answer the question
In order to leave comments, you need to log in
How correctly to display the data in xPath under such conditions?
Good evening. I have a problem that I can’t display text (3) using xPath, and is it still possible to somehow pull out a pure date from the output along with the tag. Thank you in advance.
<div class="editorial content-copy big">
<strong class="MS4CrawlHeadline">
текс 1bla-bla-bla
<br>
<br>
текс2 bla-bla-bla
</strong>
<br>
<br>
текс3 bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla bla-bla-bla
<br>
<p> Дата lalalla * 20.12.2015 </p>
<p> Дата lalalla * 20 май 2015 </p>
<p> Дата lalalla * 20 october 2015 </p>
</div>
Answer the question
In order to leave comments, you need to log in
Xpath "div/text()" will return "tex3 bla-bla-bla ..."
Try testing on this site www.xpathtester.com/xpath
If we talk about this particular piece of html code, then the text after strong can be obtained like this:
As a result, it will be necessary to go through the resulting DOMNodeList with the same foreach, because text3 is in item (1) in this particular case.
Using xpath to get the date makes no sense, you need to take the nodeValue in the desired p tag and get the date with the good old regular expression.
If we talk about your specific case, then here is the option (php):
$q = $xpath->query('//div/p');
$r = $q->item(0)->nodeValue; // самый первый параграф
preg_match('/\*(.*)/i', $r, $match);
echo trim($match[1]); // результат
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question