如何从跨html python获取文本

2024-09-30 06:33:00 发布

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

如何使用selenium在两个跨距之间获取文本

<div style="display:inline">
    <span style="margin-right:4px">£</span>
    <input type="text" name="binPrice" id="binPrice" aria-describedby="err_binPrice" value="8.95" md="dt|DOUBLE||em|Please enter a Buy it now price.||vm|Please enter a valid Buy it now price." vld="1" maxlength="10" aria-required="true">
</div>

Python

driver.find_elements_by_xpath('//span[@style="margin-right:4px"]\span')

我想得到“£”


Tags: marginrightdivstyleseleniumitbuyprice
1条回答
网友
1楼 · 发布于 2024-09-30 06:33:00

我是根据你的最新评论写的。 首先,xpath是错误的。xpath中有一个不必要的'\span'。 尝试使用:

xpath = '//span[@style="margin-right:4px"]'

其次,我注意到使用style属性不是一个好主意,因为可能有几个元素具有相同的样式。我建议使用input元素,因为它有一个ID。 所以就像:

xpath = "//input[@id='binPrice']/../span"

这将更加有力。 希望这有帮助。你知道吗

相关问题 更多 >

    热门问题