【发布时间】:2020-01-08 11:03:19
【问题描述】:
我使用蜘蛛从列表中抓取许多网站。我根据需要工作,但现在我还想获得连接状态。运行蜘蛛时,我看到一些 404、一些 301 或一些 DNS 错误。
如何将连接状态输入到我的 csv 中?
import scrapy
class CmsSpider(scrapy.Spider):
name = 'myspider'
f = open("random.csv")
start_urls = [url.strip() for url in f.readlines()]
f.close()
def parse(self, response):
title = response.xpath('//title/text()').extract_first()
url = response.request.url
description = response.xpath('//meta[@name="description"]/@content').extract_first()
yield {'URL': url, 'Page Title': title, 'Description': description}
【问题讨论】:
-
这对我来说似乎是一个解决方案。但我不知道如何与我的蜘蛛合并。