Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Ryan Mitchell, 陶俊杰, 陈小莉

Rating No ratings yet

本书采用简洁强大的Python语言,介绍了网络数据采集,并为采集新式网络中的各种数据类型提供了全面的指导。第一部分重点介绍网络数据采集的基本原理:如何用Python从网络服务器请求信息,如何对服务器的响应进行基本处理,以及如何以自动化手段与网站进行交互。第二部分介绍如何用网络爬虫测试网站,自动化处理,以及如何通过更多的方式接入网络。

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, hands-on guide to collecting data from the modern web with Python—from fetching a single page to crawling whole sites, calling APIs, and storing what you gather. Best for developers and researchers who already know some programming and want a working toolkit for real web data. 【Book Arc】 - **Opening (~0%–10%)**: Frames web scraping as a broad, cross-disciplinary skill and sets up the core loop—request HTML, parse it, store the target data, then move to the next page. - **Early (~10%–30%)**: Builds the fundamentals: requesting pages with Python's standard library, parsing messy HTML with BeautifulSoup, handling errors and redirects, and following links across sites (including a Wikipedia "six degrees" project and an intro to Scrapy). - **Early–Middle (~30%–40%)**: Shifts to structured sources—calling web APIs, working with JSON/XML, and handling authentication keys for services like Twitter and Google. - **Middle (~40%–55%)**: Covers storage and document formats: writing to CSV, using MySQL with proper Unicode handling, and extracting text from PDFs and Word files. - **Middle (~55%–70%)**: Turns to data quality—cleaning dirty data at the source, normalizing text, and using n-grams to make scraped content analyzable. - **Late–Ending (~70%–100%)**: Moves into harder territory: reading and processing images, dealing with JavaScript-rendered pages, and legal/ethical considerations for running crawlers. (Excerpts do not cover the exact chapter boundaries here.) 【Key Takeaways】 - **The scraping loop is the foundation** (Opening): fetch → parse → store → repeat. Roughly 90% of real projects reuse only these basics, so master them before chasing advanced tools. - **Robust error handling separates working crawlers from broken ones** (Early): anticipate missing pages, dead servers, and malformed data up front, or your crawler dies the moment you stop watching it. - **BeautifulSoup plus regular expressions gives flexible targeting** (Early): navigating the HTML tree by parent, sibling, and child tags—and filtering with regex—lets you locate data even when page layouts shift. - **APIs and scraping are complementary, not rivals** (Early–Middle): both send HTTP requests and return data; combining them (e.g., pairing Wikipedia edit history with an IP-geolocation API) produces richer results than either alone. - **Storage design should follow the data's structure** (Middle): modeling pages and links as separate tables with IDs and timestamps makes large crawls queryable and analyzable later. - **Unicode and encoding are persistent pain points** (Middle): configure databases and text handling for full Unicode early, or non-English content will break your pipeline. - **Dirty data must be cleaned at the source** (Middle): inconsistent casing, punctuation, and spelling are the norm; normalization and n-grams turn raw text into something analyzable. - **Not all content is plain HTML** (Late): PDFs, Word documents, images, and JavaScript-rendered pages each need their own extraction approach. 【Reading Tips】 - Deep-read the first part (requesting, parsing, error handling)—these chapters are used daily and repay careful practice. - Skim the API and storage chapters if you already know HTTP and SQL; focus instead on the Unicode and schema-design warnings. - Treat the data-cleaning chapter as a reference you'll return to; the n-gram material is more useful once you have real messy data. - Don't skip the legal/ethical appendix material—crawler etiquette and compliance matter as much as the code. - Code examples target Python 3.x; note that some tools mentioned (e.g., Scrapy) required Python 2.7 at the time of writing. 【Coverage Limits】 This guide is synthesized from stratified excerpts covering roughly the first half of the book in detail; later chapters on images, JavaScript rendering, and legal issues are only lightly represented, so specifics there are not fully covered.
Page 8
.......................................8 第 2 章 复杂 HTML 解析 ......................................................................................................
View in text
Excerpt 2
Trees)的作用。在第 1 章里,我们 看过用单一方向进行 BeautifulSoup 标签树的导航: bsObj.tag.subTag.anotherSubTag 现在我们用虚拟的在线购物网站 http://www.pythonscraping.com/pages/page3.html 作为要抓 取的示例网页...
View in text
Excerpt 3
new Key”按钮创建新的 API key。为了你的账号安全, 建议限制 API 使用的 IP 地址或 URL 链接。你也可以创建一个可用于任意 IP 地址或 URL 的 API key,只要把“Accept Request From These Server IP Addresses”(接受这些服务器 IP...
View in text
Excerpt 4
是,如果你遇到的是俄语、阿拉伯语文档,或者文档里有一个像“résumé” 这样的单词,就可能出问题。 看看下面的代码: from urllib.request import urlopen textPage = urlopen( "http://www.pythonscraping.com/pages/waran...
View in text
Excerpt 5
那么代码是怎么实现的呢? buildWordDict 函数把网上获取的演讲文本的字符串作为参数,然后对字符串做一些清理 和格式化处理,去掉引号,把其他标点符号两端加上空格,这样就可以对每一个单词进行 有效的处理。最后,再建立如下所示的一个二维字典——字典里有字典: {word_a : {word_b : 2, w...
View in text
Excerpt 6
选择器(比如 mytag#idname)一样,虽然它原本被 设计用于处理更规范的 XML 文档而不是 HTML 文档。 在 XPath 语法中有四个重要概念。 • 根节点和非根节点 ♦ /div 选择 div 节点,只有当它是文档的根节点时 ♦ //div 选择文档中所有的 div 节点(包括非根节点) 136...
View in text
Excerpt 7
nts。这个对象在第 10 章已经简单介绍过了,它 的调用方式如下所示: usernameField = driver.find_element_by_name('username') 就像你可以在浏览器里对网站上的不同元素执行一系列操作一样,Selenium 也可以对任何 给定元素执行很多操作,如下所示: my...
View in text
Excerpt 8
司来说所有加总肯定是一笔大数目)。 2003 年,加州高级法院判了另一个案子,Intel 公司起诉 Hamidi 失败。Intel 前雇员 Hamidi 通过 Intel 服务器向 Intel 的员工发送让 Intel 不爽的邮件。法院结案时说: 196 | 附录 C Google 网络缓存 Google 网络爬...
View in text
Tags
AI categories
PythonWeb TechnologyData
ISBN: 711541629X
Publish Year: 2016
Language: Chinese
Pages: 200
File Format: PDF
File Size: 16.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…