首页 > 解决方案 > 当 div 类的名称临时更改时,使用 selenium 查找网站的某些部分

问题描述

我正在尝试抓取一个网站,但它使用某种软件来更改 div 的类名称。因为我使用的技术是find_elements_by_xpath("//div[@class='classname']") 每次 div 类名更改我的解决方案失败时。我感兴趣的网站部分如下所示:

<div class="classname1"> #List of items start
 <div class="classname2"> #I want it (this is special cause its like the title)
 </div>
 <div class="classname3"> # the first item (i want it cause the divs inside it is the information of the item
  <div class = "classname4">
  </div>
  ...
  more <div class> inside
 </div>
 <div class="classname3"> #second item I am also interested in(same as the first one, i want it cause the divs inside it is the information of the item)
  <div class="classname5">
  </div>
  ...
  more <div class> inside
 </div>
# and so on
...
</div>

是否有另一种方法来本地化这些项目但避免这个问题?

标签: pythonseleniumweb-scrapingxpath

解决方案


推荐阅读