html - XPath 选择两个标题之间的所有段落?

标签 html xml xpath

我正在尝试位于两个 h5 元素之间的所有 p 元素。开始的 h5 文本是“Subject”,第二个 h5 文本是“tenders file”。

您也可以看到附件中的图片。

我不想在第二个 h5 之后出现其他 p 元素。 enter image description here

我尝试了以下 XPath:

//p[preceding-sibling::h5//*[contains(text() , 'SUBJECT')]  and following-sibling::h5//*[contains(text() , 'Tender’s Files,')]] trying to get idea from [enter link description here][2]

但找不到正确的段落。它仍然选择第二个 h5 之后的其他段落。

<div>
<table class="table table-striped table-bordered table-hover" width="90%">
<tbody>
<tr>
<td style="vertical-align: middle;" colspan="2" width="90%">
<h5 style="padding-left: 10px;"><strong><span style="color: #3577be;">Tender Title:</span>&nbsp;Testing of Non-Fortified Wheat Flour in NES</strong></h5>
</td>
</tr>
<tr>
<td style="vertical-align: middle;" width="45%">
<h5 style="padding-left: 10px;"><strong><span style="color: #3577be;">Tender No:</span>&nbsp;SYRIA-TA-2021-005</strong></h5>
</td>
<td style="vertical-align: middle;">
<h5 style="padding-left: 10px;"><strong><span style="color: #3577be;">Location:</span> North East Syria</strong></h5>
</td>
</tr>
<tr>
<td style="vertical-align: middle;" colspan="2">
<h5 style="padding-left: 10px;"><strong><span style="color: #3577be;">Tender Package Available from:</span>&nbsp;2021-01-10</strong></h5>
</td>
</tr>
<tr>
<td style="vertical-align: middle;" colspan="2">
<h5 style="padding-left: 10px;"><strong><span style="color: #3577be;">Deadline for Offer Submission:</span> 2021-01-18 17:00 (Iraqi Time)</strong></h5>
</td>
</tr>
</tbody>
</table>
<table class="table " width="90%">
<tbody>
<tr>
<td style="text-align: center;">&nbsp;</td>
</tr>
</tbody>
</table>
<h5><strong><u>SUBJECT:</u></strong>&nbsp;<strong>Testing of Non-Fortified Wheat Flour in NES</strong></h5>
<p>Our organization, a non-profit organization, provides humanitarian assistance to “people in need”, is seeking quotations from eligible contractors to&nbsp;<strong>Testing of Non-Fortified Wheat Flour in NES</strong>. Our organization anticipates awarding Multiple or Single contract(s) as a result of this Solicitation. Our organization reserves the right to award more or none under this RFQ.</p>
<p>All bids shall be submitted&nbsp;<strong>via e-mail to</strong>&nbsp;<span id="cloak1f9ac73a082c1f52174ccee4f406b81c"><a href="mailto:Syr-tendering@blumont.org"><strong>Syr-tendering@blumont.org</strong></a></span>&nbsp;<strong>as PDF format and clearly written the subject of the tender</strong>&nbsp;This RFQ is in no way obligates our organization Our organization to award a contract nor does it commit our organization to pay any cost incurred in the preparation and submission of a proposal.</p>
<p>Our organization bears no responsibility for data errors resulting from transmission or conversion processes.</p>
<p>&nbsp;</p>
<ul>
<li><strong>To help us with our procurement effort, please indicate in your email where (ngotenders.net) you saw this tender/procurement notice.</strong></li>
</ul>
<p><strong>Sincerely</strong></p>
<p><strong>Procurement Committee</strong></p>
<h5><strong>Tender’s Files,</strong></h5>
<h5><strong><a href="https://www.ngosjobs-bids.com/index.php/submit-tender/submission-view-file/73abcfe286e504282bdac61776e50907/ec8dde28a94a8fde67c09e244f6bb8a0">5ffb04ba52a49-005-announcement.zip</a>,&nbsp;</strong></h5>
<hr>
<h5 dir="rtl"><strong><u>الموضوع</u></strong><strong><u>:</u></strong>&nbsp;<strong>فحص الطحين الغير مدعم في شمال شرق سوريا.</strong><strong>&nbsp;</strong></h5>
<p dir="rtl">منظمتنا و هي منظمة غير ربحية تعمل لخدمة المنكوبين في العالم و تسعى للحصول على عروض أسعار من المقاولين المؤهلين لغرض الموضوع:&nbsp;<strong>فحص الطحين الغير مدعم في شمال شرق سوريا.</strong>&nbsp;وتتوقع منظمتنا منح (عقود) متعددة أو مفردة نتيجة لهذا الطلب. وتحتفظ منظمتنا بالحق في منح التعاقد بأكثر أو أقل من المتوقع للطلب أعلاه.</p>
<p dir="rtl">لهذا الطلب. وتحتفظ منظمتنا بالحق في منح التعاقد بأكثر أو أقل من المتوقع للطلب أعلاه.</p>
<p dir="rtl">&nbsp;يجب على جميع مقدمي العطاءات تقديم العروض عبر الايميل :<strong>عبر الايميل:&nbsp;</strong><span id="cloakc42a61e471daa10a7992dbd8b44f9b26"><a href="mailto:Syr-tendering@blumont.org"><strong>Syr-tendering@blumont.org</strong></a></span>&nbsp;<strong>و بصيغة</strong><strong>&nbsp;PDF</strong>&nbsp;و تم التوضيح للموضوع المناقصة بان المنظمة لا تلتزم بأي حال من الأحوال بمنح العقد كما أن المنظمة لا تلتزم بدفع أي تكاليف متكبدة في إعداد وتقديم العرض.</p>
<p dir="rtl">كما ان منظمتنا لا تتحمل أية مسؤولية عن أي أخطاء في البيانات الناتجة عن عمليات النقل أو التحويل او المحادثة.</p>
<p dir="rtl">
</p><p dir="rtl"><strong>مع فائق الاحترام &nbsp;و التقدير</strong></p>
<p dir="rtl"><strong>لجنة المشتريات</strong></p>
<h5><strong>Tender’s Files,</strong></h5>
<h5><strong><a href="https://www.ngosjobs-bids.com/index.php/submit-tender/submission-view-file/73abcfe286e504282bdac61776e50907/ec8dde28a94a8fde67c09e244f6bb8a0">5ffb04ba52a49-005-announcement.zip</a>,&nbsp;</strong></h5>
</div>

页面源代码。

enter link description here

最佳答案

使用以下问答中的技术:

以下 XPath,

//p[    preceding-sibling::h5[starts-with(normalize-space(),'SUBJECT:')]
    and following-sibling::h5[normalize-space()='Tender’s Files,']]

将根据要求选择两个目标标题之间的所有 p 元素。


OP 包含实际标记后的更新:

您的实际标记包括重复

<h5><strong>Tender’s Files,</strong></h5>

标题。上面的 XPath 将一直选择到最后这样的标题。

如果您只想通过第一个 这样的标题进行选择,请改用此 XPath:

//p[    preceding-sibling::h5[starts-with(normalize-space(),'SUBJECT:')]
    and following-sibling::h5[normalize-space()='Tender’s Files,']
    and not(preceding-sibling::h5[normalize-space()='Tender’s Files,'])]

关于html - XPath 选择两个标题之间的所有段落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66073818/

相关文章:

python - (不是这样)子节点到列表的高级 xsl 转换

java - 如何解析 XML 以检索嵌入的文本节点

jquery - 真正基本的 jQuery : how can I check to see if a table cell has a value?

html - HTML5 中的铰接式 3D 人

html - <br/> 在 I.E 中不工作

xml - cvc-complex-type.2.4.a : Invalid content was found starting with element 'MarkupListURI' . 预期为 '{MarkupDeleteURI}' 之一

java - 如何抓取给定标签内的字符串?

perl - 将 XPath 与 Perl 一起使用

jquery - 如何使用 jQuery 制作选择下拉列表?

java - 为什么我的启动画面不起作用?