【问题标题】:Connection to the other side was lost - webscraping与另一端的连接丢失 - 网络抓取
【发布时间】:2019-04-18 12:45:49
【问题描述】:

我想从https://www.gpw.pl/spolki 中刮取所有公司名称,此外我想按“Pokaż więcej...”(英文显示更多)刮取所有公司名称。

我的初始代码是:

import scrapy 
from scrapy.http.request import Request

from gpw_scraping.items import FinalItem

class ScrapeMovies(scrapy.Spider):
    name='GpwScraping'

    start_urls = [
        'https://www.gpw.pl/spolki'
    ]


    def parse(self, response):
        for row in response.xpath('//tbody[@id="search-result"]//tr'):

            item = FinalItem()
            item['name'] = row.xpath('//tbody[@id="search-result"]//tr/td/small/text()').extract_first()

            yield scrapy.Request( url=response.urljoin(profile_url), callback=self.parse_profile, meta={"item": item } )

        next_page_url = response.xpath('//html/body/section[2]/div[2]/div/div/div/div[3]/a').extract_first()
        if next_page_url:
           yield scrapy.Request( url=response.urljoin(next_page_url), callback=self.parse )


        yield item

但是最后我留下了以下错误:

[<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion: Connection lost.>]

如果我想要一个包含所有公司名称的 csv,我该如何实现?

我做错了什么我的意思是这个网站只是阻止我抓取?

编辑:我最好的猜测是该网站阻止了所有网络爬虫,我尝试使用不同的 IP 地址,但没有任何帮助。

顺便说一句:如果您对这个问题投了反对票,请毫不犹豫地写下原因:)

【问题讨论】:

  • 如果您以非常高的请求率访问远程服务器,脚本可能会被阻止,因为“没有人可以请求那么快”。考虑在请求之间添加延迟。
  • 并非如此 我几乎从一开始就有这个问题。我不认为我是因为请求率极高而被阻止的。
  • 尝试添加不同的用户代理
  • 同样的事情.....

标签: python web-scraping scrapy web-crawler


【解决方案1】:

是的,该网站可能会阻止您。

尝试启用Autothrottle feature 以避免对网站造成太大影响。

您也可以尝试将user-agent 设置为different value。例如。

custom_settings = {
    'DEFAULT_REQUEST_HEADERS': {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
    }
}

如果这些都对您没有帮助,请考虑使用代理或 VPN。

【讨论】:

  • 嗯....我最好的猜测是该网站阻止了网络报废。我尝试了不同的 IP 地址,但似乎没有任何效果:(
  • 您是否尝试过使用不同的用户代理?我已经编辑了我的答案。
  • 是的,正是你给的那个,还是什么都没有:/
猜你喜欢
  • 2013-09-02
  • 1970-01-01
  • 2015-12-27
  • 2014-09-03
  • 1970-01-01
  • 1970-01-01
  • 2020-05-08
  • 2015-07-27
  • 1970-01-01
相关资源
最近更新 更多