[英]Python Selenium get all elements in page source. driver.find_elements(By.XPATH, "//*")
I'm trying to get all HTML tags in page_source by using the below code我正在尝试使用以下代码获取 page_source 中的所有 HTML 标签
driver.find_elements(By.XPATH, "//*")
Most of the time it works as expected but for some rear cases (probably in bigger page_sources) it hangs and rises below the exception大多数时候它按预期工作,但对于某些后面的情况(可能在更大的 page_sources 中)它挂起并上升到异常以下
Message: stale element reference: element is not attached to the page document
Do you have any suggestions on how to fix this or another equivalent command to get all HTML elements in page_source?您对如何修复此命令或其他等效命令以获取 page_source 中的所有 HTML 元素有任何建议吗? Thank you beforehand.
预先谢谢你。
Found the issue.发现了问题。 Some elements are deleted by JS after the page is fully loaded.
一些元素在页面完全加载后被 JS 删除。 the solution is to add a try/except block whenever looping through each element as it might be deleted after the page is fully loaded.
解决方案是在循环遍历每个元素时添加一个 try/except 块,因为它可能会在页面完全加载后被删除。 I hope this makes sense.
我希望这是有道理的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.