Web scraping Scrapy Shell:twisted.internet.error.ConnectionLost,尽管已设置用户\u代理

Web scraping Scrapy Shell:twisted.internet.error.ConnectionLost,尽管已设置用户\u代理,web-scraping,scrapy,scrapy-spider,scrapy-shell,Web Scraping,Scrapy,Scrapy Spider,Scrapy Shell,当我尝试刮取某个网站(同时使用spider和shell)时,会出现以下错误: twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.>] twisted.web.\u newclie

当我尝试刮取某个网站(同时使用spider和shell)时,会出现以下错误:

twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.>]
twisted.web.\u newclient.ResponseNeverReceived:[]
我发现,当没有设置用户代理时,这种情况可能会发生。 但是在手动设置之后,我仍然得到相同的错误

您可以在此处看到scrapy shell的整个输出:

笔记: 我不支持代理,我可以通过scrapy shell访问其他网站而不会出现问题。我也可以使用Chrome访问该网站,因此这不是网络或连接问题


也许有人能给我一个提示,告诉我如何解决这个问题?

这里是100%的工作代码

您需要做的是还必须发送请求头

settings.py

# -*- coding: utf-8 -*-
import scrapy, logging
from scrapy.http.request import Request

class Test1SpiderSpider(scrapy.Spider):
    name = "test1_spider"

    def start_requests(self):

        headers = {
            "Host": "www.firmenabc.at",
            "Connection": "keep-alive",
            "Cache-Control": "max-age=0",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "DNT": "1",
            "Accept-Encoding": "gzip, deflate, sdch",
            "Accept-Language":"en-US,en;q=0.8"
        }

        yield Request(url= 'http://www.firmenabc.at/result.aspx?what=&where=Graz', callback=self.parse_detail_page, headers=headers)

    def parse_detail_page(self, response):
        logging.info(response.body)
编辑:

您可以通过检查开发工具中的URL来查看要发送的标题


那么问题出在哪里?只需设置
用户代理
,然后继续抓取。。。在ITA中,如果没有任何
用户代理
,远程网站可能会被设置为不响应任何请求。正如我所说,我在设置用户代理时也会遇到相同的错误。。我不知道下一步该去哪里。我将编辑答案,以便更好地理解。(另外,如果您查看pastebin链接,您可以看到,我设置了一个用户代理)查看我的答案。。。您必须随请求一起发送
标题
。非常感谢!我不知道标题的事。仅针对未来的问题:有没有办法找出我必须发送的标题信息?@Areiter查看我编辑的答案,也请向上投票我的答案谢谢向上投票,不幸的是我还不能向上投票答案,对不起!