簡體   English   中英

如何使用 static url 抓取多個頁面,請求方法獲取

[英]how to scrape multiple pages with static url, request method get

首先,對不起我的英語,其次,我在 python 中只有 2 周大。

現在我使用 python,模塊 selenium 和 chromedriver,我要抓取的頁面是“http://lpse.maroskab.go.id/eproc”,

from time import sleep
from selenium import webdriver
from bs4 import BeautifulSoup as bs
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("disable-extensions")
chrome_options.add_argument("disable-gpu")
chrome_options.add_argument("headless")

path =r'F:\python latian\webdriver\chromedriver.exe'

driver = webdriver.Chrome(options=chrome_options, executable_path = path)
driver.get('http://lpse.maroskab.go.id/eproc4/lelang')
sleep(5)
page=bs(driver.page_source,"html.parser")
code=page.find_all(class_="sorting_1")
for xx in code:
   kode=xx.contents[0]
   print(code)

但是使用這段代碼我只從第一頁獲取數據,而我想要完成的是抓取另一頁,然后我遇到了([this thread][1]),但該線程中的答案請求方法是“ post" ,在我的是"get" 我在那里讀到了使用“urllib.request”的建議,但我知道這種方法只有在我知道 url 時才有效。 謝謝[1]:https://stackoverflow.com/questions/48985758/how-to-scrape-multiple-pages-with-an-unchanging-url-python-3

go 有很多方法可以解決這個問題,並且迭代多個頁面並非易事,您的代碼需要大量改進。 由於您是新人,因此我將包含您需要包含的內容,並提供一個示例,您可以使用它來合並到您的代碼中。

您肯定需要使用顯式等待來等待“加載”指標的不可見性。

您還需要一個無限循環,只有當“下一頁”鏈接被禁用(沒有更多可用頁面)時,我們才會退出該循環。

是一個很好的例子,並使用@alecxe 的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM