gpt4 book ai didi

python - selenium 按包含的标题查找元素?

转载 作者:行者123 更新时间:2023-11-28 21:38:36 26 4
gpt4 key购买 nike

我需要使用 selenium 从下面的输出中找到 RSSI(4G 信号强度)。

据我所知,我是否首先需要找到包含标题 EE000000 的所有元素。然后我可以看到父 div 中的路径属性与具有相同路径的另一个子 div 匹配

例如0-7262-12686-13379在两个div中命名,一个是标题,另一个是我想要的值。

然后我需要获取以“4G 信号强度”开头的标题来获取该值,我的最终结果应该是

EE100000 -96
EE100001 -81

等等……

到目前为止,我的路径尝试未能按照下面的方法找到 EE100000 值,它试图找到一个现有的 EE 不,不是所有的 EE 不是

driver.find_element_by_xpath('//*[contains(@title, "EE100205")')
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(@title, "EE100205")' is not a valid XPath expression.

我通过以下方式将源添加为图像

下面的源代码示例:-

  <div class="slick-row  odd" row="1" style="height:29px">
<row>
<div class="slick-cell lr c0 treeColumn children00">
<div class="treeItem deviceItem cell-inner device expanded isnotfavorite remoteprobe isnotpaused" idx="1"
level="2" objid="13379" type="device" path="0-7262-12686-13379" template="_Prtg.Core.device.js">
<level last="true"></level>
<level lastx="false">
<level>
<toggler></toggler>
</level>
</level>
<div class="indent level2" title="EE100133 RS – NAME&lt;br/&gt;(6 Sensors)&lt;br/&gt;OK">
<level class="device">
<icon popup="333" style="background-image:url(/icons/devices/vendors_cradlepoint.png)"></icon>
</level>
<device>
<name popup="3333" goto="true">EE100133 - RS NAME </name>
<condition></condition>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" id="fav-13379" onclick="_Prtg.objectTools.faveObject.call(this,13379,'toggle');return false;"></span>
</favorit>
<status></status>
</device>
</div>
</div>
</div>
<div class="slick-cell lr c1 valueColumn children00">
<div class="sensorItem cell-inner c1 drop device expanded isnotfavorite remoteprobe isnotpaused" idx="1"
objid="13379" type="device" path="0-7262-12686-13379" template="_Prtg.Core.sensor.js">
<div>
<sensor idx="0" objid="13380" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="Throughput (1,19 kbit/s)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">Throughput</name>
<value goto="true">1,19 kbit/s</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13380,'toggle');return false;"></span>
</favorit>
</sensor>
<sensor idx="1" objid="13381" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="Uptime (306 d)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">Uptime</name>
<value goto="true">306 d</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13381,'toggle');return false;"></span>
</favorit>
</sensor>
<sensor idx="2" objid="13382" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="4G Signal strength (-96 #)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">4G Signal strength</name>
<value goto="true">-96 #</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13382,'toggle');return false;"></span>
</favorit>
</sensor>
<sensor idx="3" objid="13383" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="4G Signal quality (-7 #)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">4G Signal quality</name>
<value goto="true">-7 #</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13383,'toggle');return false;"></span>
</favorit>
</sensor>
<sensor idx="4" objid="13384" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="3G Signal quality (-6 #)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">3G Signal quality</name>
<value goto="true">-6 #</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13384,'toggle');return false;"></span>
</favorit>
</sensor>
<sensor idx="5" objid="13385" type="sensor" class="sensor dragable isnotpaused isnotfavorite status3"
title="Network Bearer (211 msec)">
<icon popup="333" goto="true"></icon>
<name popup="3333" goto="true">Network Bearer</name>
<value goto="true">211 msec</value>
<favorit>
<span class="objectisnotfavorite icon-gray ui-icon ui-icon-flag" onclick="_Prtg.objectTools.faveObject.call(this,13385,'toggle');return false;"></span>
</favorit>
</sensor>
</div>
</div>
</div>
</row>
</div>
<div class="slick-row even" row="2" style="height:29px">
<row>
<div class="slick-cell lr c0 treeColumn children00">
<div class="treeItem deviceItem cell-inner device expanded isnotfavorite remoteprobe isnotpaused" idx="2"
level="2" objid="14551" type="device" path="0-7262-12686-14551" template="_Prtg.Core.device.js">
<level last="true"></level>
<level lastx="false">
<level>
<toggler></toggler>
</level>
</level>

最佳答案

对于标题以“4G 信号质量”开头的元素的 CSS 选择器:

driver.find_element_by_css_selector("[title^='4G Signal quality']")

,或包含“4G信号质量”:

driver.find_element_by_css_selector("[title*='4G Signal quality']")

关于python - selenium 按包含的标题查找元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48011212/

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