【问题标题】:XPath to select all paragraphs between two headers?XPath 选择两个标题之间的所有段落?
【发布时间】:2021-05-10 10:01:20
【问题描述】:

我正在尝试位于两个 h5 元素之间的所有 p 元素。开头的h5 文本是“主题”,第二个h5 文本是“招标文件”。

您也可以看到附上的图片。

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

我尝试了以下 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

【问题讨论】:

    标签: html xml xpath


    【解决方案1】:

    使用以下问答中的技巧:

    以下 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 会选择到 last 这样的标题。

    如果您只想通过 first 这样的标题进行选择,请改用此 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,'])]
    

    【讨论】:

    • 感谢您的支持。我尝试使用您的代码,但我仍然无法获得位于这两个 h5 元素之间的段落。我更新了我的问题,还提到了该页面的链接。您能帮我解决一下吗
    • 感谢您将标记作为文本添加到您的问题中。我现在已经确认了我提供的 XPath does as you request,但是在您的实际标记中有两个 &lt;h5&gt;&lt;strong&gt;Tender’s Files,&lt;/strong&gt;&lt;/h5&gt;,并且提供的 XPath 将在选择中包含内部这样的 h5。您是否只想要 SUBJECT h5first Tender’s Files, h5 之间的元素?
    【解决方案2】:

    如果你添加这个,你的 xpath 应该可以工作:

    //p[preceding-sibling::h5//*[contains(text() , 'SUBJECT')]  and (following-sibling:: h5//*[contains(text() , 'Tender’s Files,')])[2]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多