python - 网站强制 scrapy 重定向

标签 python scrapy

我不断从 www.caribbeanjobs.com 重定向。我已经对我的蜘蛛进行了编程,使其不遵守robot.txt,禁用cookie,尝试meta=dont_redirect。我还能做什么?

下面是我的蜘蛛:

import scrapy

from tutorial.items import CaribbeanJobsItem

class CaribbeanJobsSpider(scrapy.Spider):
        name = "caribbeanjobs"
        allowed_domains = ["caribbeanjobs.com/"]
        start_urls = [
        "http://www.caribbeanjobs.com/"
        ]
        def start_requests(self):
            for url in self.start_urls:
                yield scrapy.Request(url, meta={'dont_redirect':True})

        def parse(self, response):
                if ".com" in response.url:
                        from scrapy.shell import inspect_response
                        inspect_response(response, self)

这些是我的设置:

BOT_NAME = 'tutorial'

SPIDER_MODULES = ['tutorial.spiders']
NEWSPIDER_MODULE = 'tutorial.spiders'


# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'tutorial (+http://www.yourdomain.com)'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# 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 http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'tutorial.middlewares.MyCustomSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
#    'tutorial.middlewares.MyCustomDownloaderMiddleware': 543,
#}

# Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
#    'tutorial.pipelines.SomePipeline': 300,
#}

# Enable and configure the AutoThrottle extension (disabled by default)
# See http://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 http://scrapy.readthedocs.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'

最佳答案

您是否尝试在设置中设置明确的USER_AGENT

http://doc.scrapy.org/en/latest/topics/settings.html#user-agent

类似这样的事情可能可以作为起点:

USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36"`

关于python - 网站强制 scrapy 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39132733/

相关文章:

python - 如何在 Python 中写入 csv 函数中的 float 转换字符串输出?

python - 在 Python 中从列表列表到文件

python - 有效地将二进制数据嵌入脚本

python - 从文本构建日期数组

python - 如何处理端口的突发连接?

python - 使用 scrapy 限制检索项目的数量

python - 如何编写 python scrapy 代码以提取站点站点地图中存在的 url

python - 如何在scrapy中设置json输出的键值对?

xpath - 带有text()的Scrapy Xpath包含

python - Scrapy:抓取角度 ng-href 链接?