python - scrapy - 重新启动 scrapoxy 实例?
问题描述
我已经使用scrapoxy设置了代理 我尝试设置非常保守的设置,不那么频繁地达到目标,按照这里的提示虽然我不确定我理解它的意思
从浏览器中的知名用户代理池中轮换您的用户代理(谷歌四处获取它们的列表)
这是我当前的 settings.py
# -*- coding: utf-8 -*-
BOT_NAME = 'mybot'
SPIDER_MODULES = ['ffscraper.spiders']
NEWSPIDER_MODULE = 'ffscraper.spiders'
# Crawl responsibly by identifying yourself (and your website) on the user-agent
USER_AGENT = 'myUnivProject'
# Obey robots.txt rules
ROBOTSTXT_OBEY = False
# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 5
# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 20.0
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 1
CONCURRENT_REQUESTS_PER_IP = 1
DOWNLOAD_TIMEOUT = 30
RETRY_TIMES = 0
# PROXY
PROXY = 'http://xxx.xxx.xxx.x:8888/?noconnect'
# SCRAPOXY
API_SCRAPOXY = 'http://xxx.xxx.xxx.x:8889/api'
API_SCRAPOXY_PASSWORD = 'xxxx'
DOWNLOADER_MIDDLEWARES = {
'scrapoxy.downloadmiddlewares.proxy.ProxyMiddleware': 100,
'scrapoxy.downloadmiddlewares.wait.WaitMiddleware': 101,
'scrapoxy.downloadmiddlewares.scale.ScaleMiddleware': 102,
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': None,
}
# Disable cookies (enabled by default)
COOKIES_ENABLED = False
# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False
# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
# 'Accept-Language': 'en',
#}
# Enable or disable spider middlewares
# See https://doc.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'ffscraper.middlewares.FfscraperSpiderMiddleware': 543,
#}
# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'ffscraper.middlewares.FfscraperDownloaderMiddleware': 543,
#}
# Enable or disable extensions
# See https://doc.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,
#}
# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
# 'ffscraper.pipelines.FfscraperPipeline': 300,
#}
# Enable and configure the AutoThrottle extension (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/autothrottle.html
AUTOTHROTTLE_ENABLED = True
# The initial download delay
AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False
# Enable and configure HTTP caching (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
我仍然,只有在大约 50 个请求之后,才开始被重定向到带有验证码的页面。
2019-01-04 00:17:09 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (meta refresh) to <GET https://www.asite.com/distil_r_captcha.html?requestId=xxx-xxx-xxx-xxx-xxx&httpReferrer=xxxx> from <GET https://www.asite.com/xxx/xxx>
在这里阻止重定向不是一种选择。我需要能够恢复活动。目前我唯一能做的就是停止爬虫,杀死 scrapoxy 上的虚拟机,然后重新启动爬虫。
- 我想念房间里的大象吗?我的设置有什么可以改变的吗?
- 或者,有没有办法以编程方式关闭 VM 并在重定向时重新创建一个?
有趣的是,如果我阻止重定向
yield scrapy.Request(
url="https://www.whatasite.com" + url.split("?")[0],
meta={"name": name, 'dont_redirect': True,},
callback=self.parse
)
然后我得到200
一个我无法抓取的页面(因此得到空值),而不是捕获我可能可以处理的错误代码here。
解决方案
推荐阅读
- python - 带有错误消息的 Python 中的 Project Euler 问题 2
- xml - 如何在 Nuxt.js 中创建 Google 新闻提要 (xml)?
- postgresql - 如何删除postgreSQL中相差小于10秒的重复数据
- c++ - Boost状态图:尝试实现正交状态的内部初始子状态但编译失败
- ios - React native 0.63.4 ios 14 无静态图像
- azure-functions - azure functionapp 在输出 blob 绑定上设置元数据
- vhdl - 如何在VHDL中的每个时钟周期设置一个标志
- regex - 正则表达式 - 仅在字符串的一部分中更改逗号
- python - 从类传递函数而不启动它python
- php - ACF“acf/save_post”挂钩中的 WooCommerce WC_Product set_category_ids() 方法存在问题