gpt4 book ai didi

Python 中 xpath 的 Selenium 语法

转载 作者:行者123 更新时间:2023-12-03 00:53:30 29 4
gpt4 key购买 nike

我正在尝试单击此网址 http://ecos.fws.gov/ecp0/profile/speciesProfile?sId=6994 处的文本,但无法想出正确的语法。

我想做的是点击“查看全部”,但不幸的是html中有多个“查看全部”。 html 看起来像这样:

<li style="margin-bottom:1em;">
<p><strong>Population location:</strong> Wherever found west of Mobile and Tombigbee Rivers in AL, MS, and LA</p>
<p><strong>Listing status:</strong> 
<span class="listingThreat">Threatened</span>
</p>
<ul>
<ul>
<li><b>States/US Territories</b> in which this population is known to or is believed to occur: 
<a href="/ecp0/profile/countiesByState?entityId=181&amp;state=Alabama" onclick="window.open('', 'popup', 'width=800,height=550,scrollbars=yes,resizable=yes')" target="popup">Alabama</a>
, <a href="/ecp0/profile/countiesByState?entityId=181&amp;state=Louisiana" onclick="window.open('', 'popup', 'width=800,height=550,scrollbars=yes,resizable=yes')" target="popup">Louisiana</a>
, <a href="/ecp0/profile/countiesByState?entityId=181&amp;state=Mississippi" onclick="window.open('', 'popup', 'width=800,height=550,scrollbars=yes,resizable=yes')" target="popup">Mississippi</a>
</li>
<li><b>US Counties</b> in which this population is known to or is believed to occur: 
<a href="/ecp0/profile/countiesBySpecies?entityId=181" onclick="window.open('', 'popup', 'width=800,height=550,scrollbars=yes,resizable=yes')" target="popup">View All</a></li>
<li><b>USFWS Refuges</b> in which this population is known to occur: 
Bogue Chitto National Wildlife Refuge, Egmont Key National Wildlife Refuge, Grand Bay National Wildlife Refuge, Hobe Sound National Wildlife Refuge, Mississippi Sandhill Crane National Wildlife Refuge<br/>
</li>
</ul>
</ul>
</li>

我基本上需要选择 li 样式为“margin-bottom:1em;”的位置并包含“受威胁”和“查看全部”。不幸的是,对于提供的 url,有两个“查看全部”,并且都在 style =“margin-bottome:1em;”的 li 内。

我只是想不出一种方法来唯一标识第一个“查看全部”。我正在考虑某种条件路径,但不确定

最佳答案

试试这个 xpath - "//span[@class='listingThreat']/ancestor::li//a[text()='View All']"

关于Python 中 xpath 的 Selenium 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40746273/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com