如何使用Selenium获取ID为的元素的文本

pnwntuvh  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(181)

请考虑:

<tr id="pair_12">
    <td class="left first">
        <span class="ceFlags USD">&nbsp;</span>
        &nbsp; USD
    </td>

    <td class="" id="last_12_12">1</td>
    <td class="pid-2124-last" id="last_12_17">0,8979</td>
    <td class="pid-2126-last" id="last_12_3">0,7695</td>
    <td class="pid-3-last" id="last_12_2">109,94</td>
    <td class="pid-4-last" id="last_12_4">0,9708</td>
    <td class="pid-7-last" id="last_12_15">1,3060</td>
    <td class="pid-2091-last greenBg" id="last_12_1">1,4481</td>
    <td class="pid-18-last greenBg" id="last_12_9">5,8637</td>
</tr>

我想访问,例如,“5,8637”的值,它也刷新每隔一秒左右。这是网站,也许它可以帮助你帮助我更好的link

wgxvkvu9

wgxvkvu91#

driver = Chrome(webdriver)
driver.get("https://tr.investing.com/currencies/exchange-rates-table")
eur_usd = driver.find_element_by_id("last_17_12").text

对我有用!

vof42yt1

vof42yt12#

用途:

By id = By.id("ANY_ID");

使用 getText(标识); Selenium WebDriver下的函数。

相关问题