我正在尝试使用硒抓取网页。通过检查页面并右键单击建议的 xpath 属于不稳定类型 (/html/body/table[2]/tbody/tr[1]/td/form/table/tbody/tr[2]) 。所以我尝试了以下解决方案:
driver = webdriver.Chrome("path")
driver.get("https://www.bundesfinanzhof.de/entscheidungen/entscheidungen-online")
time.sleep(1)
links=driver.find_element_by_xpath('//tr[@class="SuchForm"]')
or even
links=driver.find_elements_by_xpath('//*[@class="SuchForm"]')
不返回任何结果。然而在页面的前面我可以获得:
links=driver.find_element_by_xpath('//iframe')
links.get_attribute('src')
似乎之后:
<script language="JavaScript" src="/rechtsprechung/jscript/list.js" type="text/javascript"></script>
我无法再触及任何元素。如何确定正确的 XPath? https://stackoverflow.com/questions/31325232/how-do-i-determine-the-correct-xpath表明脚本中的某些部分无法解析。然而,我所追寻的道路在我看来并不在一条道路之内。我是否误解了脚本在页面上的工作方式?
例如,稍后有一条路径:
/html/body/table[2]/tbody/tr[1]/td/script
我预计这会造成这样的问题。我绝不是程序员,所以我对这个主题的理解是有限的。有人可以解释一下问题是什么以及如果可能的话解决方案吗?
尝试使用以下解决方案:
在 selenium-python 中使用 xpath 查找元素文本不起作用 https://stackoverflow.com/questions/41850994/find-element-text-using-xpath-in-selenium-python-not-working
xpath 不适用于该网站,请验证 https://stackoverflow.com/questions/25122873/xpath-does-not-work-with-this-site-pls-verify