python - Scrapy SitemapSpider在干净关闭后不继续
问题描述
我正在使用 JOBSDIR 使用此处的文档运行一个scrapy站点地图蜘蛛:https ://docs.scrapy.org/en/latest/topics/jobs.html 。
但是,我会彻底关机,按 ctrl + c(我已经仔细检查了多次,这是彻底关机,我没有发送 ctrl+c 两次),蜘蛛将无法继续。输出将显示“过滤的重复请求:example.com/sitemap.xml”,但在 JOBSDIR 文件夹中仍然会有大量看不见的请求和一个非常大的 requests.queue 文件。
为什么scrapy会过滤掉起点站点地图而不是使用requests.queue?显然,如果它过滤掉我提供的唯一网址,即站点地图,它将永远无法到达任何地方。有任何想法吗?
编辑:我正在做的一件事是从 python 脚本启动我的蜘蛛,而不是从 scrapy 命令行启动。这样做,也许我没有通过scrapy推荐的-s参数。“-s”有什么作用?这个变量的文档在哪里?
process = CrawlerProcess({'JOBDIR': '.jobs/alexa_site_' + str(alexa_site_id)})
MySpider.set_settings(alexa_site)
MySpider.custom_settings[
'USER_AGENT'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"
process.crawl(MySpider, alexa_site_id=alexa_site_id)
process.start()
这是蜘蛛代码:
class MySpider(SitemapSpider):
custom_settings = {
'RANDOMIZE_DOWNLOAD_DELAY': True,
'MEMUSAGE_ENABLED': True,
'DOWNLOAD_TIMEOUT': 20,
'DEPTH_LIMIT': 100000,
'LOG_LEVEL': 'CRITICAL',
'DOWNLOADER_MIDDLEWARES': {
'rotating_proxies.middlewares.RotatingProxyMiddleware': 610,
'rotating_proxies.middlewares.BanDetectionMiddleware': 620,
},
'ROTATING_PROXY_BAN_POLICY': 'spiders.classes.proxies.policy.MyPolicy',
'ROTATING_PROXY_PAGE_RETRY_TIMES': 20,
'ROTATING_PROXY_LOGSTATS_INTERVAL': 5,
'ROTATING_PROXY_CLOSE_SPIDER': True,
'RETRY_HTTP_CODES': [500, 502, 503, 504, 522, 524, 408, 403],
'DEPTH_PRIORITY': 1,
'SCHEDULER_DISK_QUEUE': 'scrapy.squeues.PickleFifoDiskQueue',
'SCHEDULER_MEMORY_QUEUE': 'scrapy.squeues.FifoMemoryQueue',
'TELNETCONSOLE_USERNAME': 'scrapy',
'TELNETCONSOLE_PASSWORD': 'scrapy',
'DUPEFILTER_DEBUG': True
}
name = None
allowed_domains = []
sitemap_urls = ['https://www.example.com/sitemap.xml']
def parse(self, response):
le = LinkExtractor()
links = le.extract_links(response)
for link in links:
yield response.follow(link.ur, self.parse)
解决方案
推荐阅读
- date - 在两个不同的日期范围之间过滤 pyspark 数据帧行
- xamarin.forms - 如何根据开关输入显示/隐藏 xamarin 表单内容页面中的条目?
- visual-studio - VSCode 中仍然存在错误的终端仿真器
- python - 如何将 JSON 文件中的值提取到数据框行中的单独列中
- java - 下载管理器视频无法播放
- r - 为什么写入文件时编码会发生变化?
- laravel - “npm run dev”上的错误(在 Laravel 全新安装之后)
- python - 如何通过其中一个键值将我的字典中的值居中?
- php - 在 WooCommerce 管理订单页面中更改订单项目显示的元键标签
- r - 如何使用 somSC 类型图进行多重绘图?