这是我的瘙痒蜘蛛
class Spider(scrapy.Spider):
name = "name"
start_urls = ["https://www.aurl"]
def parse(self, response):
links_page_urls = response.css("a.dynamic-linkset::attr(href)").extract()
for url in contract_page_urls:
yield response.follow(url, callback=self.parse_list_page)
next_data_cursor = response.css("li.next").css("a::attr(href)").extract_first()
if next_data_cursor:
self.log("going to next page - {}".format(next_data_cursor))
yield response.follow(next_data_cursor, callback=self.parse)
def parse_list_page(self, response):
list = response.css("div.row div.list-group a.list-group-item").css("a::attr(href)").extract()
for url in list:
self.log("url - {}".format(url))
yield scrapy.Request(url=self.base_url + url, callback=self.parse_page)
def parse_page(self, response):
#Lots of code for parsing elements from a page
# build an item and return it
我的观察结果是,在我家自己的机器上,没有
download delay
设置后,实际页面会连续快速访问并保存到mongo。当我将此代码移动到EC2实例并将下载延迟设置为60时,我现在注意到的是,访问网页不是为了刮取,而是访问第一个页面,刮取下一个数据令牌并访问它。然后,我看到了很多与删除列表页相关的打印输出,而不是每个单独的页面。
所需的行为是访问初始URL,获取页面列表,然后访问每个页面并将其刮除,然后移动到下一个数据光标并重复此过程。