2024-04-26 07:07:25 发布
网友
如何使用pythonwebdriver在html标记之间放置文本?在
<!--html cod--> <span class="py"></span> <!--I want to put text between span tag with python WebDriver like this--> <span class="py">text</span>
您可以在添加文本之前使用selenium获取元素,然后使用javascript在元素末尾后立即插入文本。在
例如:
node = driver.find_element_by_xpath("//span[@class='py']") script = "arguments[0].insertAdjacentHTML('afterEnd', arguments[1])" driver.execute_script(script, node, "the new text")
下面是一个完整的工作示例,假设该网站至少有一个div(在我撰写本文时,它是这样做的):
您可以在添加文本之前使用selenium获取元素,然后使用javascript在元素末尾后立即插入文本。在
例如:
下面是一个完整的工作示例,假设该网站至少有一个div(在我撰写本文时,它是这样做的):
^{pr2}$相关问题 更多 >
编程相关推荐