Skip to Content
Python和NLTK实现自然语言处理
book

Python和NLTK实现自然语言处理

by Posts & Telecom Press, Nitin Hardeniya
February 2024
Intermediate to advanced
649 pages
9h 58m
Chinese
Packt Publishing
Content preview from Python和NLTK实现自然语言处理

第7章 网络爬取

非结构化文本的最大资源库是Web。如果你知道如何抓取Web数据,那么你就拥有的随时可用于实验的数据。因此,对NTLK感兴趣的人值得学习网络爬取技术。本章探讨的就是从网络中收集数据的知识。

在本章中,我们将使用称为Scrapy的Python库来编写网络爬虫程序。我们将提供根据要求配置不同设置所有的详细信息。我们将编写一些最常见的网络蜘蛛策略和多个用例。如果读者需要使用Scrapy,那么读者也需要了解Xpath、爬取(crawling)、刮取(scraping),以及与Web相关的一些常见概念。在读者实现这些技术之前,我们将会探讨这些主题,确保读者理解了这些技术的实际应用方面。在本章结束之前,读者将对网络爬虫有一个更加深入的理解。

  • 可以使用Scrapy来编写网络爬虫。
  • 了解关于Scrapy的所有主要功能。

最大的网络爬虫是谷歌,谷歌爬取了整个万维网(WWW)。谷歌遍历了网络上现存的所有网页,刮取/爬取了全部内容。

网络爬虫是计算机程序,它系统性地、一页又一页地浏览网页,同时刮取/爬取网页中的内容。网络爬虫也可以从所爬取的内容中,解析出待访问的下一组URL。因此,如果这些进程无限期地在整个Web上运行,那么我们可以爬取所有网页。网络爬虫也可以称为蜘蛛、机器人和抓取器(scraper)。这些称呼的意思都是相同的。

在编写第一个网络爬虫之前,我们还要思考几个要点。在每一次网络爬虫遍历网页的时候,我们必须确定我们希望选择和忽略的内容。对于搜索引擎这样的应用程序,我们应该忽略所有的图片、JS文件、CSS文件和其他文件,只集中在可以索引并显示为搜索结果的HTML内容。在一些信息提取引擎中,我们选择了特定标签或特定的网页部分。如果要递归地进行爬取,那么还需要提取网址。这就涉及了爬取策略这个主题。此处,需要确定是以深度优先的方式,还是以广度优先的方式,递归地进行爬取。可以沿着下一个网页中的某个URL,以深度优先的方式前进,直到我们得到了所需的URL,或者可以以广度优先的方式,访问下一个网页中的所有URL,递归地这样操作。 ...

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

Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton
Spark机器学习实战

Spark机器学习实战

Posts & Telecom Press, Siamak Amirghodsi, Meenakshi Rajendran, Broderick Hall, Shuen Mei

Publisher Resources

ISBN: 9781835083451