Python Data Scraping: Techniques and Practice cover

Python Data Scraping: Techniques and Practice

No rating yet
Word count
410K words
Chapters
40
ISBN
9787121298844

Tags

Summary

Using Python as its implementation language, this book follows the complete chain of "getting data—analyzing data—presenting data" and is organized into three parts—data scraping, data analysis, and data visualization—each relatively independent so that readers can read selectively. Chapter 1 opens with a complete small example that walks readers through installing the Python environment, using pip, and looking up help, while quickly reviewing the language elements that later chapters will inevitably use: file operations, loops, exceptions, tuples, lists, dictionaries, sets, random numbers, and enumerate. Chapter 2 focuses on string parsing, introducing common string functions, regular expressions, BeautifulSoup, and JSON structures as a foundation for extracting useful information from web page text. Chapter 3 moves into single-machine data scraping, covering the basic workflow of sequential scraping, use of the requests library, and concurrent and parallel scraping. Chapter 4 expands the perspective to distributed systems, introducing RPC calls and the Celery task system. Chapter 5 is devoted to Selenium, covering single-machine scraping, distributed scraping, and running under Linux without a graphical interface, for pages that depend on script rendering. Chapter 6 discusses the problem of IP blocking during scraping, explaining Tor installation and use, multithreaded approaches, and integration with Selenium. Chapter 7 collects common difficult scenarios such as Flash, desktop applications, USB drives, secondary and tertiary pages, image processing, and App data scraping. Chapter 8 presents the design and examples of a monitoring framework, and Chapter 9 briefly introduces the Hadoop ecosystem and setting up a Cloudera environment as groundwork for subsequent processing of massive data. Throughout, the book emphasizes applying mature principles and popular frameworks to concrete problems, with runnable example code that readers can run and modify, turning the examples into scraping programs suited to their own needs.

Editor's review

市面上的爬虫书大致分两类:一类只讲requests加BeautifulSoup写几个静态页面,另一类一上来就是Scrapy全家桶。这本2016年的书走的是中间路线,它把“抓取”当成一个工程问题来拆:先用第1至2章补齐Python和字符串解析的基本功,再用第3至4章讲清单机与分布式的差别,然后用Selenium和Tor两章专门处理动态页面与IP封锁这两类最让人头疼的实战障碍。 比较有意思的是第7章。Flash、桌面程序、U盘、二三级页面、图片、App数据抓取,这些碎问题在多数教程里不会单独成章,却是实际做项目时真正卡住人的地方;作者把它们集中列出,像一份“踩坑清单”,很适合边做边查。第8章的监控框架和结尾的Hadoop生态圈,则把视野从“抓到一条数据”拉到“持续稳定地抓、抓完怎么存怎么算”。 需要提醒的是,书出版于2016年,示例基于当时的Python 2/早期Python 3、requests、Selenium与Celery版本,Tor、Flash、App抓取等章节的具体操作与环境变化较大,直接照抄代码可能跑不通。把它当作理解抓取技术版图与问题分类的路线图,配合官方文档更新细节,收益最大。

Who it's for

A good fit for

  • 已掌握Python基础语法,想系统入门网络数据抓取的开发者
  • 需要处理动态渲染页面、IP封锁等实战障碍的爬虫从业者
  • 数据分析岗人员,希望自己动手获取外部公开数据的读者
  • 高校计算机相关专业学生,用作数据采集课程参考书

Not a good fit for

  • 完全没有编程经验、需要从零学Python的纯新手
  • 想直接学习Scrapy、Playwright等现代框架最新用法的人
  • 只关心数据分析建模、不打算自己写抓取程序的读者

Reading tips

  1. 先跑通第1章的两个小实例,把环境与pip源配好,再进入第2章字符串解析。
  2. 第3至6章建议边读边敲代码,每章结束后改造示例去抓一个自己感兴趣的真实页面。
  3. 第7章可当工具书使用,遇到具体问题(动态加载、App数据、图片等)时再回查对应小节。
  4. 注意代码年代,requests、Selenium、Celery的API已有变化,遇到报错优先查官方文档而非硬抄书中写法。

About the publisher

Publishing House of Electronics Industry China · Founded in 1982

The Publishing House of Electronics Industry is a comprehensive publisher distinguished by its focus on electronic information and related fields. Judging from the more than 3,000 titles in its catalogue, its publishing covers programming and design, artificial intelligence, computer science, finance and economics, photography, and social sciences, attending both to cutting-edge technology and to general readers. Representative titles include Factor Investing: Methods and Practice, x86 Assembly Language: From Real Mode to Protected Mode, The RISC-V Reader, Artificial Intelligence: Speech Recognition, Understanding and Practice, Phased Array Radar Technology, Radar Target Characteristics, and 100 Go Mistakes and How to Avoid Them, most of which centre on technical methods and engineering practice. Its authors include Shi Chuan, Li Zhong, Wang Xiaobo, David Patterson, Andrew Waterman, and Yu Zihao, among others from China and abroad. Owing to limited public information, no further publishing features are elaborated here.

Contents

  1. Chapter 1 Python Basics
  2. 1.1 Installing Python
  3. 1.2 Installing pip
  4. 1.3 How to Look Up Help
  5. 1.4 The First Example
  6. 1.5 File Operations
  7. 1.6 Loops
  8. 1.7 Exceptions
  9. 1.8 Tuples
  10. 1.9 Lists
  11. 1.10 Dictionaries
  12. 1.11 Sets
  13. 1.12 Random Numbers
  14. 1.13 Using enumerate
  15. 1.14 The Second Example
  16. Chapter 2 String Parsing
  17. 2.1 Common Functions
  18. 2.2 Regular Expressions
  19. 2.3 BeautifulSoup
  20. 2.4 JSON Structures
  21. Chapter 3 Single-Machine Data Scraping
  22. 3.1 Single-Machine Sequential Scraping
  23. 3.2 requests
  24. 3.3 Concurrent and Parallel Scraping
  25. Chapter 4 Distributed Data Scraping
  26. 4.1 Using RPC
  27. 4.2 The Celery System
  28. Chapter 5 The Versatile Selenium
  29. 5.1 Single-Machine Scraping with Selenium
  30. 5.2 Distributed Scraping with Selenium
  31. 5.3 Using Selenium on Linux Without a Graphical Interface
  32. Chapter 6 The Mysterious Tor
  33. 6.1 The Problem of IP Blocking During Scraping
  34. 6.2 Installing and Using Tor
  35. 6.3 Multithreaded Use of Tor
  36. 6.4 Combining Tor with Selenium
  37. Chapter 7 Common Scraping Problems
  38. 7.1 Flash
  39. 7.2 Desktop Applications
  40. 7.3 USB Drives

FAQ

这本书适合零基础学Python的人吗?
不太适合。虽然第1章有Python基础内容,但篇幅紧凑,只覆盖安装、文件、循环、异常和几种容器,更像为后续章节做的快速铺垫。没有编程经验的读者建议先单独学一门Python入门课,再回来看这本书。
书里的代码现在还能直接运行吗?
书中示例基于2016年前后的Python与第三方库版本,requests、Selenium、Celery的接口和浏览器驱动机制此后都有较大变化,Tor、Flash、Cloudera相关操作的环境也变了。核心思路仍然有效,但细节需要对照官方文档调整。
书名叫“数据抓取技术与实战”,为什么有数据分析和可视化内容?
按出版社的内容简介,本书按数据抓取、数据分析、数据可视化三部分组织,目的是打通从获取数据到分析展示的完整流程,且各部分相对独立。实际章节以抓取技术为主体,后续与大数据处理衔接。
作者是谁?
本书由潘庆和、赵星驰编著,2016年8月由电子工业出版社出版。潘庆和毕业于哈尔滨工业大学计算机科学与技术学院,获工学博士学位,后在哈尔滨商业大学计算机与信息工程学院任教。
和Scrapy类爬虫书相比有什么区别?
本书不围绕某一个爬虫框架展开,而是按问题分类讲技术:字符串解析、单机与分布式抓取、Selenium、Tor、常见疑难场景、监控框架。它更像一份技术地图和踩坑清单,适合用来理解问题全貌,而非系统学习某个框架。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

More by the same author

Top rated in the same category