python - Scrapy 产生深度为 2 的请求
问题描述
因此,我无法从一个从起始parse
方法向下请求 2 个请求的函数进行日志记录。这是代码:
from datetime import datetime
import scrapy
import requests
import re
import os
class ScrapyTest(scrapy.Spider):
"""
Generic crawler
"""
name = "test"
start_urls = [
'http://www.reddit.com',
]
def __init__(self, *args, **kwargs):
super(ScrapyTest, self).__init__(*args, **kwargs)
def parse(self, response):
"""
Entry point for the crawler
"""
self.logger.debug('starting off in the parse function')
yield scrapy.Request(self.start_urls[0], callback=self.parse_hw_post)
def parse_hw_images(self, image_links):
self.logger.debug("inside parse_hw_images about to scrapy request parse_hw_image")
yield scrapy.Request(self.start_urls[0], callback=self.parse_hw_image)
def parse_hw_image(self, response):
self.logger.debug('inside ________internal________ parse hw image')
yield 'test string to yield in to'
def parse_hw_post(self, response):
# Save the images to a tmp directory for now
self.logger.debug('in parse_hw_post')
self.parse_hw_images('whatever')
现在唯一显示的日志是Starting off in the parse function
然后inside parse_hw_images about to scrapy request parse_hw_image
预期的行为将是:
解析
parse_hw_post
parse_hw_images
parse_hw_image
谁能看到我在做什么?
解决方案
yield scrapy.Request(self.start_urls[0], callback=self.parse)
意味着您正在parse
使用相同的 URL 调用相同的方法,因此 scrapy 将其过滤为重复的 URL。
设置DUPEFILTER_DEBUG=True
为查看重复的 URL。
推荐阅读
- odoo - 如何复制报价/订单报告并自定义复制?
- python - 如何绘制 GAN 生成器部分的训练精度?
- c# - 如何从 stringformat 显示 99.99 中的 100
- c# - 如何查询 Entity Framework Core 生成的连接表或通用表?
- python - 使用 GridSearchCV 进行 Ridge 回归的验证曲线结果和平均分数
- show - 有没有可以让 iHome 插头闪烁音乐的应用程序?
- swift - 线程 1:spritekit 中的信号 SIGABRT/sigterm
- opencv - 使用 CNN 的轮廓检测
- html - _includes 中的 HTML 未显示使用 Jekyll 包含的位置
- html - 如何让表单外的按钮与表单内的按钮对齐?