{"title":"import scrapy\nfrom scrapy.linkextractors import LinkExtractor\nfrom scrapy.spiders import CrawlSpider, Rule\n\n\nclass SunSpider(CrawlSpider):\n name = 'sun'\n #allowed_domains = ['www.sun.com']\n start_urls = ['https://www.kuaidaili.com/free/inha/1/']\n #链接提取器 LinkExtractor(allow=r'Items/')\n rules = (\n Rule(LinkExtractor(allow=r'https://www.kuaidaili.com/free/inha/\d+/'), callback='parse_item', follow=False),\n )\n\n def parse_item(self, response):\n print(response)为什么打印为空\n内容:您的代码存在问题,无法正常打印response。原因是在parse_item函数中,您没有返回任何内容。应该在函数中添加返回语句来返回response,如下所示:\n\npython\ndef parse_item(self, response):\n print(response)\n return response\n\n\n这样就可以正常打印response了。"}

Scrapy 爬虫:打印response为空的解决方法