Amazon动态更改CSS浏览器和HTML对象的名称?

2024-10-06 11:30:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Selenium构建了一个Amazon.es web scraper

我使用CSS选择器来查找总页数(以确定循环将迭代多少次)

但是每天,我都必须返回并更新选择器名称,因为它似乎是动态变化的

我不太擅长HTML/CSS,他们是怎么做到的

昨天起作用的选择器:

lastPage = browser.find_elements_by_css_selector('div.s-desktop-width-max.s-desktop-content.sg-row > div.sg-col-20-of-24.sg-col-28-of-32.sg-col-16-of-20.sg-col.sg-col-32-of-36.sg-col-8-of-12.sg-col-12-of-16.sg-col-24-of-28 > div > span:nth-child(5) > div.s-main-slot.s-result-list.s-search-results.sg-row > div:nth-child(58) > span > div > div > ul > li:nth-child(6)')

今天起作用的选择器:

lastPage = browser.find_elements_by_css_selector('div.s-desktop-width-max.s-desktop-content.sg-row > div.sg-col-20-of-24.sg-col-28-of-32.sg-col-16-of-20.sg-col.sg-col-32-of-36.sg-col-8-of-12.sg-col-12-of-16.sg-col-24-of-28 > div > span:nth-child(5) > div.s-main-slot.s-result-list.s-search-results.sg-row > div:nth-child(51) > span > div > div > ul > li:nth-child(6)')


Tags: ofdivbrowserchild选择器colelementsfind