我已使用scrapoxy设置了代理 我尝试设置非常保守的设置,并按照提示here很少达到目标,尽管我不确定我理解
的含义。从浏览器中的一系列知名用户代理中轮换您的用户代理 (谷歌搜索以获得它们的列表)
这是我当前的设置。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>
here中的阻止重定向是不可选项。我需要能够恢复活动。目前,我唯一能做的就是停止搜寻器,使用scrapoxy杀死VM,然后重新启动搜寻器。
有趣的是,如果我阻止重定向
yield scrapy.Request(
url="https://www.whatasite.com" + url.split("?")[0],
meta={"name": name, 'dont_redirect': True,},
callback=self.parse
)
然后我得到200
和一个我无法抓取的页面(因此获取空值),而不是捕获我也许可以像在here中那样处理的错误代码。