Skip to Content
Python数据处理
book

Python数据处理

by Jacqueline Kazil, Katharine Jarmul
July 2017
Intermediate to advanced
398 pages
11h 54m
Chinese
Posts & Telecom Press
Content preview from Python数据处理
网页抓取:获取并存储网络数据
237
如果在
JavaScript
控制台中使用
jQuery
JavaScript
很容易与你的内容交互,
那么使用
Python
处理可能也会很简单。如果使用
jQuery
选择一个元素很困
难,或者在一个页面上可以使用的代码在另一个相似的页面上不起作用,很
可能在
Python
中也同样困难。
不能使用
Python
工具正确解析的网页少之又少。我们会教给你一些技巧,来应对混乱的网
页、内联
JavaScript
、格式化糟糕的选择器,以及你能在万维网的代码中发现的所有糟糕
的选择,同时还会给出一些最佳实践。首先,看看加载和读取网页。
11.3
 得到页面
如何通过互联网发出请求
网页抓取器的第一步是……连接到互联网。让我们温习一下连接互联网的一些基础知识。
当你打开浏览器,输入一个站点名称或者搜索词,并且敲击回车键的时候,你正在发出一
请求
。大多数情况下,这是一个
HTTP
(超文本传输协议)请求(或者
HTTPS
——安全
版本的
HTTP
协议)。你很可能在创建一个
GET
请求,这是在互联网上使用的众多
请求方
一(
https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
)。浏览
器会处理这些请求,同时解析输入,以确定你是在请求一个网站还是一个搜索词。根据该
分析结果,浏览器会返回搜索结果或你请求的网站。
让我们看一下用于请求
URL
Python
内置库:
urllib
https://docs.python.org/2/library/ ...
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

数据科学中的实用统计学(第2版)

数据科学中的实用统计学(第2版)

Peter Bruce, Andrew Bruce, Peter Gedeck
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115459190