Scrapy 是 Python 开发的一个快速、高层次的屏幕抓取和 Web 抓取框架,用于抓取 Web 站点并从页面中提取结构化的数据。Scrapy 用途广泛,可以用于数据挖掘、监测和自动化测试。
Scrapy 吸引人的地方在于它是一个框架,任何人都可以根据需求方便的修改。它也提供了多种类型爬虫的基类,如 BaseSpider、sitemap 爬虫等,最新版本又提供了 Web2.0 爬虫的支持。
Scrapy 是一个开放源码和协作框架,用于从网站中提取您需要的数据,以一种快速,简单,但可扩展的方式。
- pip install scrapy
-
- cat > myspider.py <h2'):
- yield {'title': title.css('a ::text').get()}
-
- for next_page in response.css('a.next-posts-link'):
- yield response.follow(next_page, self.parse)
-
- EOF
-
- scrapy runspider myspider.py
- pip install shub
- shub login
- Insert your Scrapinghub API Key:
-
- # Deploy the spider to Scrapy Cloud
- shub deploy
-
- # Schedule the spider for execution
- shub schedule blogspider
- Spider blogspider scheduled, watch it running here:
- https://app.scrapinghub.com/p/26731/job/1/8
-
- # Retrieve the scraped data
- shub items 26731/1/8
- {"title": "Improved Frontera: Web Crawling at Scale with Python 3 Support"}
- {"title": "How to Crawl the Web Politely with Scrapy"}
- ...
编写规则来提取数据,然后让Scrapy来完成其余的工作。
可扩展的设计,插入新的功能很容易,而不必触及核心。
用Python编写,在Linux、Windows、Mac和BSD上运行