【问题标题】:Python / Scrapy: yield request without callbackPython / Scrapy:产生没有回调的请求
【发布时间】:2017-08-30 03:53:53
【问题描述】:

我正在尝试输入 getMonthEvents。但不知何故,回调似乎永远不会执行。有任何想法吗?谢谢:)

from scrapy.selector import Selector
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy.http import Request
from scrapy.item import Item, Field

class EventItems(Item):
    Title = Field()
    Link = Field()
    Date = Field()
    Time = Field()
    Place =  Field()
    Description = Field()
    Program=Field()

class SpiderForHSMT(CrawlSpider):
    name = 'HMTM'
    start_urls = ['http://www.some_website.com']
    rules =(Rule( LinkExtractor(restrict_xpaths=('//div[@id="VER_2013_DISPLAYSEARCHRESULTS"]/table[1]/tr[3]'), tags=('a',), attrs=('href',)), callback = 'parseMonth'), )

    def parseMonth(self, response):
        request = Request(response.url, callback = self.getMonthEvents)
        yield request

    def getMonthEvents(self, response):
        print(response.url)

【问题讨论】:

    标签: python scrapy


    【解决方案1】:

    当您在 parseMonth 中复制请求时,请求会被过滤为重复项(see documentation)。将dont_filter=True 添加到您的请求中,以便它们不会被过滤。

    request = Request(response.url, dont_filter=True, callback = self.getMonthEvents)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 1970-01-01
      相关资源
      最近更新 更多