将 Scrapy over Splash 与 HTTP 代理结合使用时出现“500 内部服务器错误”

2023-12-12

我正在尝试使用 Splash (以渲染 JavaScript)和 Tor 通过 Privoxy (以提供匿名性)在 Docker 容器中爬行 Scrapy 蜘蛛。这里是docker-compose.yml我正在为此使用:

version: '3'

services:
  scraper:
    build: ./apk_splash
    # environment:
      # - http_proxy=http://tor-privoxy:8118
    links:
      - tor-privoxy
      - splash

  tor-privoxy:
    image: rdsubhas/tor-privoxy-alpine

  splash:
    image: scrapinghub/splash

其中 Scraper 有以下内容Dockerfile:

FROM python:alpine
RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl bash
RUN pip install scrapy scrapy-splash scrapy-fake-useragent
COPY . /scraper
WORKDIR /scraper
CMD ["scrapy", "crawl", "apkmirror"]

我试图爬行的蜘蛛是

import scrapy
from scrapy_splash import SplashRequest
from apk_splash.items import ApkmirrorItem

class ApkmirrorSpider(scrapy.Spider):
    name = 'apkmirror'
    allowed_domains = ['apkmirror.com']
    start_urls = [
        'http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/',
    ]

    custom_settings = {'USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}

    def start_requests(self):
        for url in self.start_urls:
            yield SplashRequest(url=url, callback=self.parse, endpoint='render.html', args={'wait': 0.5})

    def parse(self, response):
        item = ApkmirrorItem()
        item['url'] = response.url
        item['developer'] = response.css('.breadcrumbs').xpath('.//*[re:test(@href, "^/(?:[^/]+/){1}[^/]+/$")]/text()').extract_first()
        item['app'] = response.css('.breadcrumbs').xpath('.//*[re:test(@href, "^/(?:[^/]+/){2}[^/]+/$")]/text()').extract_first()
        item['version'] = response.css('.breadcrumbs').xpath('.//*[re:test(@href, "^/(?:[^/]+/){3}[^/]+/$")]/text()').extract_first()
        yield item

我添加了以下内容settings.py:

SPIDER_MIDDLEWARES = {
    'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}

DOWNLOADER_MIDDLEWARES = {
    'scrapy_splash.SplashCookiesMiddleware': 723,
    'scrapy_splash.SplashMiddleware': 725,
    'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
}

SPLASH_URL = 'http://splash:8050/'

DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'

随着environment为了scraper容器注释掉了,Scraper 或多或少可以工作。我收到包含以下内容的日志:

scraper_1      | 2017-07-11 13:57:19 [scrapy.core.engine] DEBUG: Crawled (200) <GET http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/ via http://splash:8050/render.html> (referer: None)
scraper_1      | 2017-07-11 13:57:19 [scrapy.core.scraper] DEBUG: Scraped from <200 http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/>
scraper_1      | {'app': 'Androbench (Storage Benchmark)',
scraper_1      |  'developer': 'CSL@SKKU',
scraper_1      |  'url': 'http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/',
scraper_1      |  'version': '5.0'}
scraper_1      | 2017-07-11 13:57:19 [scrapy.core.engine] INFO: Closing spider (finished)
scraper_1      | 2017-07-11 13:57:19 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
scraper_1      | {'downloader/request_bytes': 1508,
scraper_1      |  'downloader/request_count': 3,
scraper_1      |  'downloader/request_method_count/GET': 2,
scraper_1      |  'downloader/request_method_count/POST': 1,
scraper_1      |  'downloader/response_bytes': 190320,
scraper_1      |  'downloader/response_count': 3,
scraper_1      |  'downloader/response_status_count/200': 2,
scraper_1      |  'downloader/response_status_count/404': 1,
scraper_1      |  'finish_reason': 'finished',
scraper_1      |  'finish_time': datetime.datetime(2017, 7, 11, 13, 57, 19, 488874),
scraper_1      |  'item_scraped_count': 1,
scraper_1      |  'log_count/DEBUG': 5,
scraper_1      |  'log_count/INFO': 7,
scraper_1      |  'memusage/max': 49131520,
scraper_1      |  'memusage/startup': 49131520,
scraper_1      |  'response_received_count': 3,
scraper_1      |  'scheduler/dequeued': 2,
scraper_1      |  'scheduler/dequeued/memory': 2,
scraper_1      |  'scheduler/enqueued': 2,
scraper_1      |  'scheduler/enqueued/memory': 2,
scraper_1      |  'splash/render.html/request_count': 1,
scraper_1      |  'splash/render.html/response_count/200': 1,
scraper_1      |  'start_time': datetime.datetime(2017, 7, 11, 13, 57, 13, 788850)}
scraper_1      | 2017-07-11 13:57:19 [scrapy.core.engine] INFO: Spider closed (finished)
apksplashcompose_scraper_1 exited with code 0

但是,如果我在environment行中的docker-compose.yml,我收到 500 内部服务器错误:

scraper_1      | 2017-07-11 14:05:07 [scrapy.downloadermiddlewares.retry] DEBUG: Gave up retrying <GET http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/ via http://splash:8050/render.html> (failed 3 times): 500 Internal Server Error
scraper_1      | 2017-07-11 14:05:07 [scrapy.core.engine] DEBUG: Crawled (500) <GET http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/ via http://splash:8050/render.html> (referer: None)
scraper_1      | 2017-07-11 14:05:07 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <500 http://www.apkmirror.com/apk/cslskku/androbench-storage-benchmark/androbench-storage-benchmark-5-0-release/androbench-storage-benchmark-5-0-android-apk-download/>: HTTP status code is not handled or not allowed
scraper_1      | 2017-07-11 14:05:07 [scrapy.core.engine] INFO: Closing spider (finished)
scraper_1      | 2017-07-11 14:05:07 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
scraper_1      | {'downloader/request_bytes': 3898,
scraper_1      |  'downloader/request_count': 7,
scraper_1      |  'downloader/request_method_count/GET': 4,
scraper_1      |  'downloader/request_method_count/POST': 3,
scraper_1      |  'downloader/response_bytes': 6839,
scraper_1      |  'downloader/response_count': 7,
scraper_1      |  'downloader/response_status_count/200': 1,
scraper_1      |  'downloader/response_status_count/500': 6,
scraper_1      |  'finish_reason': 'finished',
scraper_1      |  'finish_time': datetime.datetime(2017, 7, 11, 14, 5, 7, 866713),
scraper_1      |  'httperror/response_ignored_count': 1,
scraper_1      |  'httperror/response_ignored_status_count/500': 1,
scraper_1      |  'log_count/DEBUG': 10,
scraper_1      |  'log_count/INFO': 8,
scraper_1      |  'memusage/max': 49065984,
scraper_1      |  'memusage/startup': 49065984,
scraper_1      |  'response_received_count': 3,
scraper_1      |  'retry/count': 4,
scraper_1      |  'retry/max_reached': 2,
scraper_1      |  'retry/reason_count/500 Internal Server Error': 4,
scraper_1      |  'scheduler/dequeued': 4,
scraper_1      |  'scheduler/dequeued/memory': 4,
scraper_1      |  'scheduler/enqueued': 4,
scraper_1      |  'scheduler/enqueued/memory': 4,
scraper_1      |  'splash/render.html/request_count': 1,
scraper_1      |  'splash/render.html/response_count/500': 3,
scraper_1      |  'start_time': datetime.datetime(2017, 7, 11, 14, 4, 46, 717691)}
scraper_1      | 2017-07-11 14:05:07 [scrapy.core.engine] INFO: Spider closed (finished)
apksplashcompose_scraper_1 exited with code 0

简而言之,当使用 Splash 渲染 JavaScript 时,我无法成功使用HttpProxy中间件以便也通过 Privoxy 使用 Tor。有人能看到这里出了什么问题吗?

Update

根据保罗的评论,我尝试改编splash服务如下:

  splash:
    image: scrapinghub/splash
    volumes:
      - ./splash/proxy-profiles:/etc/splash/proxy-profiles

我在主目录中添加了一个“splash”目录,如下所示:

.
├── apk_splash
├── docker-compose.yml
└── splash
    └── proxy-profiles
        └── proxy.ini

and proxy.ini reads

[proxy]

host=tor-privoxy
port=8118

据我了解,这应该使代理始终被使用(即whitelist默认为".*" and no blacklist).

然而,如果我再一次docker-compose build and docker-compose up,我仍然收到 HTTP 500 错误。那么问题来了,如何解决这些问题呢?

(顺便说一句,这个问题似乎类似于https://github.com/scrapy-plugins/scrapy-splash/issues/117;但是,我没有使用 Crawlera,所以我不确定如何调整答案)。

Update 2

在保罗的第二条评论之后,我查了一下tor-privoxy通过执行以下操作在容器内解析(当它仍在运行时):

~$ docker ps -l
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS               NAMES
04909e6ef5cb        apksplashcompose_scraper   "scrapy crawl apkm..."   2 hours ago         Up 8 seconds                            apksplashcompose_scraper_1
~$ docker exec -it $(docker ps -lq) /bin/bash
bash-4.3# python
Python 3.6.1 (default, Jun 19 2017, 23:58:41) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname('tor-privoxy')
'172.22.0.2'

至于我如何运行 Splash,它是通过链接的容器,类似于中描述的方式https://splash.readthedocs.io/en/stable/install.html#docker-folder-sharing。我已经验证过/etc/splash/proxy-profiles/proxy.ini存在于容器中:

~$ docker exec -it apksplashcompose_splash_1 /bin/bash
root@b091fbef4c78:/# cd /etc/splash/proxy-profiles
root@b091fbef4c78:/etc/splash/proxy-profiles# ls
proxy.ini
root@b091fbef4c78:/etc/splash/proxy-profiles# cat proxy.ini
[proxy]

host=tor-privoxy
port=8118

我会尝试Aquarium,但问题仍然是为什么当前设置不起作用?


遵循以下结构Aquarium项目建议保罗·特姆布斯,我发现给.ini文件命名是必须的default.ini, not proxy.ini(否则它不会被自动“拾取”)。我设法让刮刀以这种方式工作(参见我的自我回答如何在 Docker Compose 中通过 Privoxy 将 Scrapy 与 Splash 和 Tor 结合使用).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Scrapy over Splash 与 HTTP 代理结合使用时出现“500 内部服务器错误” 的相关文章

随机推荐

  • 不使用存储库模式,按原样使用 ORM (EF)

    我总是使用存储库模式 但对于我最新的项目 我想看看是否可以完善它的使用以及 工作单元 的实现 我开始挖掘得越多 我开始问自己这个问题 我真的需要它吗 现在这一切都始于 Stackoverflow 上的几条评论 可以追溯到 Ayende Ra
  • Rails:使用控制器渲染 js.erb 模板

    我有一个 Rails 应用程序试图合并一些 AJAX 其中单击 新建 会打开一个模式窗口和一个表单 我希望能够在失败时显示验证错误 因此在我的创建操作中 我考虑重新渲染 new js erb 文件 这是正确的方法吗 def create p
  • Android 谷歌标签管理器

    我正在按照我的营销团队的要求为 Android 应用程序 V4 实施 Google 跟踪代码管理器以供将来使用 而且我从未在网站的 GTM 上工作过 所以在这种情况下我很天真 我已经根据官方网站上的说明创建了帐户 容器和标签 我已将标签管理
  • 填充八位字节字符串

    我有 65 个不同位长度的参数 我需要将它们填充为八位字节字符串 参数将连续填充在八位字节字符串中 例如 假设第一个参数是 1 位长 因此它将填充在八位位组字符串的第 1 个八位位组的第 0 位位置 现在第二个参数假设为 9 位长 因此 该
  • 子类中的重载运算符

    游览和导游 导游扩展了旅游类别 我在旅游类中超载了 gt 运算符 我的旅游课程看起来像 include
  • cakephp中的save和saveAll函数有什么区别?

    任何人都可以举个例子吗 save用于简单地保存模型 Array ModelName gt Array fieldname1 gt value fieldname2 gt value 假设上述信息存储在名为 data 的数组中 则可以调用 t
  • WCF REST 文件上传

    我正在开发一个 WCF Web 服务 它需要能够上传文件等 目前我添加 平面图 项目的方法如下所示 OperationContract WebInvoke Method GET ResponseFormat WebMessageFormat
  • 如何生成相关的 Uniform[0,1] 变量

    这个问题与如何生成具有不同分布的相关变量的数据集 在 Stata 中 假设我创建一个遵循 Uniform 0 1 分布的随机变量 set seed 100 gen random1 runiform 我现在想要创建第二个随机变量 它与第一个随
  • JAXB 错误:有多个映射。由于两个对象工厂具有相同的 Bean

    我有两个 Maven JAXB 项目 A 主要 Maven JAXB 存根 XSD 项目 其中包含 BASKET xsd B Maven JAXB 存根想要将 BASKET xsd 包装在自己的对象中的用户项目 这会产生两个对象工厂 不同的
  • 如何在 GitHub 上合并远程更改?

    第一次尝试 Github 推送时出现以下错误 rejected master gt master non fast forward error failed to push some refs to email protected me m
  • masm32 调用 stdout 没有输出

    我正在使用 masm32 在 Windows 7 上编译和链接 它与下面的代码一起工作得很好 然而 调用 stdOut 并不是简单地在命令提示符上打印任何内容 我究竟做错了什么 386 model flat stdcall option c
  • 如何制作一个互动节目?

    我正在学习 Ocaml 我需要创建一个可以通过以下方式与用户交互的程序 Program Welcome User command1 arg1 arg2 program The answer is User command2 arg prog
  • 在这种情况下如何在 Racket 上订购我的累积变量?

    出于教育原因 我使用 Racket 进行编码 我收到了一项任务 其中我应该创建一个函数 在没有过滤器的情况下 它将接收一个列表作为输入 并仅返回另一个列表 其中包含第一个列表的偶数 我提出了迭代过程的递归定义 define add even
  • 使用向量的 r 子集数组

    我觉得这个问题应该已经有了答案 但我没有找到 我有一个数组 我想使用向量对其进行子集化 我知道如何以困难的方式做到这一点 但我确信一定有一种简单的方法 有任何想法吗 这是我的例子 dat lt data frame a rep letter
  • Spring Boot + Hibernate + Postgres - 不创建表

    我正在尝试基于实体生成架构表 应用程序正确启动 生成 SQL 但没有结果 没有创建任何表 怎么了 我在没有 Spring Boot 的情况下在普通 Spring MVC Hibernate JPA 中使用了相同的设置 并且一切正常 这是我的
  • 为什么Python的嵌套函数不称为闭包?

    我在 Python 中见过并使用过嵌套函数 它们与闭包的定义相匹配 那么为什么它们被称为 嵌套函数 而不是 闭包 呢 嵌套函数不是闭包 因为它们不被外部世界使用吗 UPDATE 我正在阅读有关闭包的内容 这让我开始思考这个关于 Python
  • 需要帮助将 BMP 图像转换为 [R] 中的矩阵吗?

    我对 R 非常陌生 我想知道是否有一种简单的方法可以将 BMP 图像转换为 R 中的矩阵 主要是 我正在寻找任何可以提供帮助的包 矩阵中每个元素的值对应于颜色 在 CRAN 软件包列表中搜索 bmp 就会出现bmp和其他一些 为了简洁起见
  • 禁用用户在 BottomSheet 上拖动

    我正在尝试禁用用户拖动BottomSheet 我想禁用的原因有两件事 1 它可以防止ListView向下滚动 2 我不希望用户使用拖动来消除 而是使用BottomSheetView 这就是我所做的 bottomSheetBehavior B
  • 基本条件覆盖与复合条件覆盖

    I m trying to get my head around the differences between these 2 coverage criteria and I can t work out how they differ
  • 将 Scrapy over Splash 与 HTTP 代理结合使用时出现“500 内部服务器错误”

    我正在尝试使用 Splash 以渲染 JavaScript 和 Tor 通过 Privoxy 以提供匿名性 在 Docker 容器中爬行 Scrapy 蜘蛛 这里是docker compose yml我正在为此使用 version 3 se