我想通过点击多个网页来检索信息(见图 1 和 2)。问题是 a) 没有下一个按钮和 b) 即使页面链接包含一个用于计数的数字,它也不会对手动更改编号做出反应(即不加载下一页)。这使任务变得棘手。任何人都可以帮助解决这个问题吗?这是链接的结构(无功能页面) https://sample.io/address/ID#pageSize=100在 Robbie W 的帮助下开始工作 .. 我使用的代码是:options.add_argument('windows-size = 1200 x 800')browser = webdriver.Chrome(chrome_options = options)browser.get('URL')page_soup_1 = soup(browser.page_source, "lxml")items_1 = page_soup_1.find_all("li", {"class": "page-item" })LenofPage = pd.DataFrame()count = pd.DataFrame()for item in items_1 : string = str(item) Num = string[string.find('page-item')+23:string.find('\/li')-8] LenofPage = LenofPage.append({'LenofPage': Num}, ignore_index = True)Max_pagenum = LenofPage.max()Max_pagenum_1 = int(Max_pagenum)count = 1#items_1 = page_soup.find_all("li", {"class": "page-item active" }).next_siblingwhile count < Max_pagenum_1: link = browser.find_element_by_xpath('//li[contains(@class, "page-item") and contains(@class,"active")]/following-sibling::li/a') link.click() count = count + 1 time.sleep(3)print(count)
1 回答

慕娘9325324
TA贡献1783条经验 获得超4个赞
当您到达最后几页时,这可能需要稍微修改,但我建议使用 XPath 查找li
当前选定的旁边的li
,然后单击其中的a
标记。
//li[contains(@class, "page-item") and contains(@class,"active")]/following-sibling::li/a
添加回答
举报
0/150
提交
取消