gpt4 book ai didi

python - 如何在抓取网页时单击下一步按钮

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:47 24 4
gpt4 key购买 nike

我正在使用包含多页信息的 scrapy 抓取网页,我需要程序单击下一个按钮,然后抓取下一页,然后继续这样做,直到抓取所有页面。但我不知道该怎么做,我只能抓取第一页。

from scrapy_splash import SplashRequest
from ..items import GameItem

class MySpider(Spider):
name = 'splash_spider' # Name of Spider
start_urls = ['http://www.starcitygames.com/catalog/category/10th%20Edition'] # url(s)
def start_requests(self):
for url in self.start_urls:
yield SplashRequest(url=url, callback=self.parse, args={"wait": 3})
#Scraping
def parse(self, response):
item = GameItem()
for game in response.css("tr"):
# Card Name
item["Name"] = game.css("a.card_popup::text").extract_first()
# Price
item["Price"] = game.css("td.deckdbbody.search_results_9::text").extract_first()
yield item

最佳答案

Documentation对此非常明确:

from scrapy_splash import SplashRequest
from ..items import GameItem

class MySpider(Spider):
name = 'splash_spider' # Name of Spider
start_urls = ['http://www.starcitygames.com/catalog/category/10th%20Edition'] # url(s)
def start_requests(self):
for url in self.start_urls:
yield SplashRequest(url=url, callback=self.parse, args={"wait": 3})
#Scraping
def parse(self, response):
item = GameItem()
for game in response.css("tr"):
# Card Name
item["Name"] = game.css("a.card_popup::text").extract_first()
# Price
item["Price"] = game.css("td.deckdbbody.search_results_9::text").extract_first()
yield item

next_page = response.css(<your css selector to find next page>).get()
if next_page is not None:
yield response.follow(next_page, self.parse)

关于python - 如何在抓取网页时单击下一步按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56257948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com