我想通過點(diǎn)擊多個(gè)網(wǎng)頁來檢索信息(見圖 1 和 2)。問題是 a) 沒有下一個(gè)按鈕和 b) 即使頁面鏈接包含一個(gè)用于計(jì)數(shù)的數(shù)字,它也不會(huì)對手動(dòng)更改編號做出反應(yīng)(即不加載下一頁)。這使任務(wù)變得棘手。任何人都可以幫助解決這個(gè)問題嗎?這是鏈接的結(jié)構(gòu)(無功能頁面) 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貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊
當(dāng)您到達(dá)最后幾頁時(shí),這可能需要稍微修改,但我建議使用 XPath 查找li
當(dāng)前選定的旁邊的li
,然后單擊其中的a
標(biāo)記。
//li[contains(@class, "page-item") and contains(@class,"active")]/following-sibling::li/a
添加回答
舉報(bào)
0/150
提交
取消