【发布时间】: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