硒按标题查找包含?

2024-04-20 09:38:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

然后我需要得到以“4G信号强度”开头的标题才能得到这个值,我的最终结果应该是

EE100000 -96
EE100001 -81

等等。。。

到目前为止,我的路径尝试未能找到如下所示的EE100000值,即试图找到现有的EE no,而不是所有EE not

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>

Tags: namedivtrueuivaluedevicesensorlevel
1条回答
网友
1楼 · 发布于 2024-04-20 09:38:35

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

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

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

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

相关问题 更多 >