【发布时间】:2021-09-15 03:34:37
【问题描述】:
这里是 Python 新手。全部1个月大。我试图抓取页面中的大多数元素,我能够处理它们并与它们交互。有两个元素具有我无法处理的动态标签。源页面如下所示
<span class="a-button-inner">
<input class="a-button-input" type="submit" aria-labelledby="Ae8MCi-55">
<span id="Ae8MCi-55" class="a-button-text" aria-hidden="true">Add Your Key</span>
</span>
每次刷新标签都是新的,所以我无法获得固定的 XPATH。有多个项目具有跨度类“a-button-inner”以及输入类“a-button-input”,并且在页面的其余部分还有其他提交按钮。唯一独特的是 Span 文本“添加您的密钥”。
感谢所有帮助以获取提交按钮元素并单击/提交它。
from selenium import webdriver
.
.
.
.
# objAddKey = driver.find_element_by_xpath('//*[@id="Ae8MCi-55"]/span/input') does not work as second round its a different XPath
objAddKey = driver.find_element_by_link_text('Add Your Key') # hoping this will get a sibling and then to get the parent and then look for all the children. I don't even know if its possible in python.
objAddKey.click()'
试图通过跨度文本搜索搜索,并遇到了一些其他的东西, https://www.tutorialspoint.com/how-to-get-text-found-between-span-selenium
WebElement l = driver.findElement(By.xpath("//p/span"));
String s = l.getText();
但这也无济于事。
https://selenium-python.readthedocs.io/locating-elements.html 经历了这个,但也没有太大帮助。
感谢您的帮助和指点。
谢谢。
【问题讨论】: