Skip to Content
Python文本分析
book

Python文本分析

by Jens Albrecht, Sidharth Ramachandran, Christian Winkler
August 2022
Intermediate to advanced
441 pages
11h 26m
Chinese
China Electric Power Press Ltd.
Content preview from Python文本分析
72
3
获得指向所有文档的
URL
。然后,我们可以通过这些
URL
下载文档,并将内容提
取到
Pandas
的数据框中。
通过本章的学习,你将对下载
HTML
和提取数据的各种方法有一个很好的了解。你
将学习如何利用
Python
提供的各种方法来提取内容。我们将介绍一个下载和提取数
据的完整示例。在实际的工作中,你可以选择适合的框架。在本章中,我们将介绍
一些提取常用元素的标准案例,可供你反复使用。
3.2
抓取网页与提取数据
抓取网页是一个复杂的过程,通常包括三个阶段,如图
3-1
所示。
HTML网站
URL生成
站点地图
存档
爬取
下载
提取
正则表达式
HTML
解析程序
头部信息
启发式
持久保存
3-1:抓取过程示意图
第一步,我们必须生成网站上所有感兴趣的内容的
URL
。接下来,我们可以使用不
同的工具,通过相应的
URL
下载页面。
最后,我们从下载的页面中提取出有用的
数据,此阶段我们可以使用不同的策略。当然,永久保存提取到的数据也非常重要。
在本章中,我们将使用
Pandas
的数据框,其中提供了各种持久性机制。
抓取网页并非必不可少,你可以使用已有的数据集来源
在许多情况下,数据集都是现成的,而且可以打包下载。这些特殊的数据集一
般都会关注某些特殊的内容或特殊情况。如果你对情感检测感兴趣,则可以
考虑如下两个被频繁使用的影评数据集:互联网电影数据库(Internet Movie
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精益AI

精益AI

Lomit Patel
构建知识图谱

构建知识图谱

Jesus Barrasa, Jim Webber
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9787519864446