我使用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)')
我不知道你想完成什么。但是,您可以通过使用xpath使用正则表达式
相关问题 更多 >
编程相关推荐