如何使用静态网址抓取多个页面,请求方法获取

问题描述 投票:0回答:1

首先,对不起我的英语,其次,iam的Python才2周大。

现在我使用python,模块硒和chromedriver,我要抓取的页面是“ http://lpse.maroskab.go.id/eproc4/lelang”,我使用的代码是这个:

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),但该线程中请求方法的答案是“ post”,而我的回答是“ get”。我阅读了有关使用“ urllib.request”的建议,但据我所知,这种方法仅在我知道url的情况下有效。谢谢

javascript python selenium screen-scraping
1个回答
0
投票

有很多方法可以解决这个问题,并且在多个页面上进行迭代并非易事,您的代码将需要大量的添加。由于您是新手,因此我将提供您需要包括的内容,并给出一个示例,您可以使用该示例将其合并到您的代码中。

您肯定需要使用Explicit Waits等待“加载”指示器的隐身状态。

您还需要一个无限循环,仅当“下一页”链接被禁用(没有更多页面可用时,我们才会退出)。>

this为例。

© www.soinside.com 2019 - 2024. All rights reserved.