当前位置:网站首页>爬虫01-爬虫基本原理讲解
爬虫01-爬虫基本原理讲解
2022-07-05 18:20:00 【闪闪发亮的小星星】
文章目录
1. 什么是爬虫
请求网站并提取数据的自动化程序.
2. 爬虫基本流程
- 发起请求
- 获取响应内容
- 解析内容
- 保存数据

3. 什么是request与Response

3.1 Request 中包含什么

请求方式: 主要有get post
* 查看请求方式

* 请求方式的类别
HTTP/1.0
1. GET:偏向于获取的方式
大部分都是给后端一些参数,用来获取些列数据
2. POST:偏向于给服务器一些数据
大部分都是登录,给服务器一些信息,你给我一个简单的结果
3. PUT:偏向于给服务器一些信息,但是是添加使用
大部分做注册, 给服务器一些信息,你把这个信息存起来
4. HEAD:用来获取服务器头信息
HTTP/1.1
5. DELETE:偏向于删除
大部分是删除评论,删除微博
6. CONNECT:管道连接改变代理连接使用【不常用】
7. PATCH: 偏向于给服务器一些信息,偏向于修改一些信息
大部分用于完善用户资料
8. OPTIONS:用于获取服务器性能,但是需要服务端同意
* get 与 post 的区别

请求URL
URL:统一资源定位符
请求头
请求的配置信息
请求体
请求体一般在get 方式时么有请求体
在post 方式时,以form data 的形式出现,包含登录信息等。
3.2Response 包含什么

响应状态
状态码: 200 成功, 300: 跳转 404:找不到
响应头
响应体
preview 内的内容
4 实例引入
import requests
r = requests.get('https://www.baidu.com/')
print(type(r))
print(r.status_code)
print(type(r.text))
print(r.text)
print(r.cookies)
输出:
<class 'requests.models.Response'>
200
<class'str'>
<html>
<head>
<script>
location.replace(location.href.replace("https://","http://"));
</script>
</head>
<body>
<noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript>
</body>
</html>
<RequestsCookieJar[<Cookie BIDUPSID=992C3B26F4C4D09505C5E959D5FBC005 for .baidu.com/>, <Cookie
PSTM=1472227535 for .baidu.com/>, <Cookie __bsi=15304754498609545148_00_40_N_N_2_0303_C02F_N_N_N_0
for .www.baidu.com/>, <Cookie BD_NOT_HTTPS=1 for www.baidu.com/>]>
分别输出了 Response 的类型、状态码、响应体的类型、内容以及 Cookies。
通过运行结果可以发现,它的返回类型是 requests.models.Response,响应体的类型是字符串 str,Cookies 的类型是 RequestsCookieJar。
使用 get 方法成功实现一个 GET 请求,这倒不算什么,更方便之处在于其他的请求类型依然可以用一句话来完成,示例如下:
r = requests.post('http://httpbin.org/post')
r = requests.put('http://httpbin.org/put')
r = requests.delete('http://httpbin.org/delete')
r = requests.head('http://httpbin.org/get')
r = requests.options('http://httpbin.org/get')
5 能抓怎样的数据

6 怎样来解析

7 为什么我抓到的和浏览器中看到的不一样
抓到的是Javascript格式,需要进行ajax等解析
8 怎样解决JavaScript渲染的问题

9 怎样保存数据

边栏推荐
- What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
- Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
- Electron安装问题
- LeetCode 6109. Number of people who know the secret
- Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
- Simulate the hundred prisoner problem
- Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
- The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
- node_ Exporter memory usage is not displayed
- Thoroughly understand why network i/o is blocked?
猜你喜欢

《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!

LeetCode 6111. 螺旋矩阵 IV
![含重复元素取不重复子集[如何取子集?如何去重?]](/img/b2/d019c3f0b85a6c0d334a092fa6c23c.png)
含重复元素取不重复子集[如何取子集?如何去重?]

About statistical power

Failed to virtualize table with JMeter

Use JMeter to record scripts and debug

Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection

Image classification, just look at me!

Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection

node_ Exporter memory usage is not displayed
随机推荐
Logical words in Articles
Thoroughly understand why network i/o is blocked?
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
吳恩達團隊2022機器學習課程,來啦
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
ClickHouse(03)ClickHouse怎么安装和部署
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
Use of print function in MATLAB
生词生词生词生词[2]
Image classification, just look at me!
从类生成XML架构
关于服装ERP,你想知道的都在这里了
MATLAB中print函数使用
ViewPager + RecyclerView的内存泄漏
LeetCode 6109. 知道秘密的人数
Generate classes from XML schema
Electron installation problems
vulnhub之darkhole_2
How can cluster deployment solve the needs of massive video access and large concurrency?
爱因斯坦求和einsum