Learning Scrapy 笔记

1. 命令行在项目根目录,根据crawl模版创建名为test的spider,web指spider可爬取的域名url,
   scrapy提供了诸多模版
    scrapy genspider –t crawl test web

2. scrapy抓取中文结果默认是unicode,无法显示中文
    在setting设置 FEED_EXPORT_ENCODING = 'utf-8'

3. 并发下载数量限制,默认为8个
    CONCURRENT_REQUESTS_PER_DOMAIN = 1

4. 请求间的延迟
    DOWNLOAD_DELAY = 5

5. 请求不去重
    scrapy.Request()增加参数 dont_filter = True

6. ValueError: Missing scheme in request url
    scrapy.Request(response.urljoin(link))

7. scrapy shell 报错403 shell里加个UA头
    scrapy shell -s USER_AGENT='Mozilla/5.0' url_link

8. 代码没问题,取不到数据,无报错,一般是xpath有问题,可使用scrapy shell调试xpath
    xpath在chrome能取到数据,在scrapy不一定能取到

9. 爬取到指定数量的item后关闭爬虫,scrapy也提供了定时关闭方法
    CLOSESPIDER_ITEMCOUNT = 10

10. 数据消除空格和'\n'
    extract()获取到列表后使用[0]切片,使用strip()方法 .extract()[0].strip()
    .replace(old_str, new_str)    替换字符串
    .split(' / ')    删除指定参数,返回切割后的字符串列表

Paperback: 270 pages Publisher: Packt Publishing - ebooks Account (January 30, 2016) Language: English ISBN-10: 1784399787 ISBN-13: 978-1784399788 Key Features Extract data from any source to perform real time analytics. Full of techniques and examples to help you crawl websites and extract data within hours. A hands-on guide to web scraping and crawling with real-life problems and solutions Book Description This book covers the long awaited Scrapy v 1.0 that empowers you to extract useful data from virtually any source with very little effort. It starts off by explaining the fundamentals of Scrapy framework, followed by a thorough description of how to extract data from any source, clean it up, shape it as per your requirement using Python and 3rd party APIs. Next you will be familiarised with the process of storing the scrapped data in databases as well as search engines and performing real time analytics on them with Spark Streaming. By the end of this book, you will perfect the art of scarping data for your applications with ease What you will learn Understand HTML pages and write XPath to extract the data you need Write Scrapy spiders with simple Python and do web crawls Push your data into any database, search engine or analytics system Configure your spider to download files, images and use proxies Create efficient pipelines that shape data in precisely the form you want Use Twisted Asynchronous API to process hundreds of items concurrently Make your crawler super-fast by learning how to tune Scrapy's performance Perform large scale distributed crawls with scrapyd and scrapinghub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值