Python Selenium - 单击没有下一步按钮的页面

我想通过点击多个网页来检索信息(见图 1 和 2)。问题是 a) 没有下一个按钮和 b) 即使页面链接包含一个用于计数的数字,它也不会对手动更改编号做出反应(即不加载下一页)。这使任务变得棘手。

任何人都可以帮助解决这个问题吗?

这是链接的结构(无功能页面) https://sample.io/address/ID#pageSize=100

http://img1.mukewang.com/60c869da0001efeb08760053.jpg

http://img3.mukewang.com/60c869e3000125ca06530436.jpg

在 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_sibling


while 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)


三国纷争
浏览 328回答 1
1回答

慕娘9325324

当您到达最后几页时,这可能需要稍微修改,但我建议使用 XPath 查找li当前选定的旁边的li,然后单击其中的a标记。//li[contains(@class,&nbsp;"page-item")&nbsp;and&nbsp;contains(@class,"active")]/following-sibling::li/a
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python