Web Scraping with Python: Collecting Data from the Modern Web is an introductory book on web scraping techniques written by Ryan Mitchell and translated by Tao Junjie and Chen Xiaoli. Published in 2016 by Posts & Telecom Press as part of its Turing Programming Series, it is based on the original English edition from O'Reilly Media. The book is divided into two parts, with 14 chapters and 3 appendices. Part One, "Building Scrapers," covers the fundamentals of data collection: starting with sending requests to servers using urllib, it explains how to use BeautifulSoup for parsing and navigating the parse tree, regular expressions and lambda expressions, traversing a single domain and recursive scraping of an entire site, and also introduces the Scrapy framework. It then covers the basic concepts and calling conventions of APIs (Echo Nest, Twitter, Google, and others), JSON parsing, and methods for storing data in files, CSV, and MySQL, along with demonstrations of reading data from encoded text, CSV, PDF, Word, and other documents. Part Two, "Advanced Scraping," confronts practical difficulties: cleaning dirty data with OpenRefine and Python, basic natural language processing with NLTK; handling form submission, login, and cookies with Requests; dealing with JavaScript-rendered pages using Selenium (and PhantomJS at the time); processing text in images with Pillow and OCR techniques, and discussing how to circumvent anti-scraping mechanisms such as CAPTCHAs; finally, website automation testing with unit tests and Selenium, and remote scraping via proxy servers and Tor. Appendices A, B, and C introduce Python, internet fundamentals, and the legal and ethical constraints of web scraping, respectively. The book is compact (about 200 pages, 280,000 characters), focusing on building an overall knowledge map and providing runnable examples rather than delving into advanced performance topics such as concurrency and clustering. The author also reminds readers: before scraping, one should understand the robots protocol and relevant laws, and respect website rights and user privacy.
如果你想从「会写 Python」跨到「能用 Python 把网上的数据弄下来」,这本书是性价比很高的起点。它不追求工具大全,而是按真实工作流展开:先发请求、再解析 HTML、然后遍历站点、调用 API、存储数据,最后处理脏数据和登录、JavaScript、验证码这些最容易卡住人的环节。每章都配示例代码,读完能立刻改造成自己项目里的脚本。 更难得的是,作者是真正做过爬虫项目的一线工程师,讲得实在:什么时候该用 API 而不是硬爬、HTML 结构变了怎么办、数据存 CSV 还是数据库、requests 与 Selenium 各管什么。附录还专门讨论法律与道德约束,提醒读者在动手之前先想清楚边界,这在同类书里并不多见。 需要提醒的是,本书 2016 年出版,书中不少工具与网站接口已发生变化(如 Twitter API、PhantomJS 已弃用),部分示例需要按新版文档调整。把它当作建立知识框架和思路的读物,而不是逐字照抄的代码手册,收获会更大;追求更新的读者可以再对照同书的第 2 版。
Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.