在 JMeter 中使用 Xpath 解析 HTML

问题描述 投票:0回答:1

我无法通过以下请求提取 Google 在搜索过程中找到的资源的链接(页面:https://google.com/search?q=example):

//div[contains(@class, 'g')]//a[descendant::h3]/@href.

一段 HTML 的示例:

             <div class="N54PNb BToiNc cvP2Ce" data-snc="pTmkif">
              <div class="kb0PBd cvP2Ce A9Y9g jGGQ5e" data-snf="x5WNvb" data-snhf="0">
               <div class="yuRUbf">
                <div>
                 <span jscontroller="msmzHf" jsaction="rcuQ6b:npT2md;PYDNKe:bLV6Bd;mLt3mc"><a jsname="UWckNb" href="https://ru.wikipedia.org/wiki/%D0%93%D0%BE%D0%B4" data-ved="2ahUKEwjq8e-bmf6HAxXNPxAIHS7EGq4QFnoECB0QAQ" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://ru.wikipedia.org/wiki/%25D0%2593%25D0%25BE%25D0%25B4&amp;ved=2ahUKEwjq8e-bmf6HAxXNPxAIHS7EGq4QFnoECB0QAQ"><br>
                   <h3 class="LC20lb MBeuO DKV0Md">Год — Википедия</h3>
                   <div class="notranslate HGLrXd NJjxre iUh30 ojE3Fb">
                    <div class="q0vns">

此类链接有效:

//div\[contains(@class, 'g')\]//a/@href
html xml parsing xpath jmeter
1个回答
0
投票

我认为您需要将 XPath 查询修改为:

//div[contains(@class, 'g')]/descendant::a[following::h3]/@href

enter image description here

更多信息:

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.