使用 Python + Selenium 到 select div 中 class 的 div 内的标签?

Using Python + Selenium to select a tag within divs of a class within a div?

好吧,我要做的是在具有特定 ID 的 div 中搜索特定 class 的 div 中的第一个标签.使用 Python + Selenium offcourse.

现在我有我的代码

newest_elements = driver.find_elements_by_css_selector("div.elements > a")

这是在用 class“元素”搜索页面中的所有 div,并从那些 div 中获取最上面的 link秒。但我不想使用 class“元素”搜索整个页面上的所有 div。我只想搜索另一个更大的 div 中的“元素”div,其特定 ID 称为“list-all”。

我该如何实现?在此先感谢您的帮助

根据你的描述而不是

newest_elements = driver.find_elements_by_css_selector("div.elements > a")

你应该使用

newest_elements = driver.find_elements_by_css_selector("div#list-all div.elements > a")

您可以在此处添加等待/延迟。