PHP - Returning all paragraphs up to first <h2>
Wikipedia articles have this structure:
<div id="bodyContent">
<div id="siteSub">...</div>
<div id="contentSub"></div>
<div id="jump-to-nav">...</div>
<table class="infobox vevent">...</table>
<p>Article summary</p>
<p>Article summary continued</p>
<p>Article summary continued</p>
开发者_如何学运维 <table id="toc" class="toc">...</table>
<h2>...</h2>
<p>...</p>
<p>...</p>
</div>
I am interested in the summary part. With Xpath, I want to say:
Return <p>
nodes inside #bodyContent
from the start AND stop as soon as you encounter the first <h2>
How do I say this?
I think you want something like //div[@id="bodyContent"]/h2[1]/preceding-sibling::p
.
This says "from #bodyContent
's children, find the first h2
element and among its preceding siblings find all p
elements".
精彩评论