• python爬虫和前端(部分)


    requests基本用法

    什么是爬虫

    获取网络数据(公开的网络)

    爬虫的基本流程

    第一步:获取网络数据(requests、selenium)

    第二步:解析数据:从获取到的网络数据中提取有效数据(正则、bs4、lxml)

    第三步:保存数据(csv、excel、数据等)

    requests

    python获取网络数据的第三方库(基于http或者https协议的网络请求)

    爬虫使用requests的两个场景:直接请求网页地址、对提供网页数据的数据接口发送请求

    requests基本用法

    对目标网页直接发送请求

    response = requests.get(网页地址)

    获取指定页面的数据返回一个响应对象

    import requests
    
    response = requests.get('https://cd.zu.ke.com/zufang')
    print(response)     #     200 - 请求成功
    
    • 1
    • 2
    • 3
    • 4

    获取响应的状态码

    print(response.status_code)
    if response.status_code == 200:
        pass
    
    • 1
    • 2
    • 3

    获取响应头

    print(response.headers)
    
    • 1

    请求内容(返回的真正有用的数据)

    1)response.content - 二进制类型的数据:图片、视频、音频等
    例如:图片下载

    2)response.text - 字符串类型的数据:网页\

    3)response.json() - 对请求内容做完json解析后的数据:json数据接口

    div标签(盒子标签)

    将一个范围中涉及到的所有的标签会放到一起。

    div {
    				/* 默认页面的宽度是固定的,高度是无限的。 */
    				width: 100%;
    				height: 264px;
    				border-top: 5px solid red;
    				border-bottom: 5px solid green;
    				border-left:  5px solid blue;
    				border-right: 5px solid black;
    			}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    CSS样式

    CSS代码就是写在中的,可以放在head标签或者body标签内。

    内部样式表:将style标签放到head标签或者body标签内。

    内联样式:可以把样式直接作为一个标签的属性,写入到标签中,使用style属性。

    外部样式:有一个后缀名为.css的文件专门用来存放CSS代码,只需要在html代码中使用link标签将CSS文件引入即可。

    link标签语法:

    如果rel为icon,表示给页面标签页设置图标,type为image/图片格式,表示引入xxx格式的图片
    rel=“icon” type=“image/图片格式(png、jpg)” href=“图片的链接和路径”

    rel为stylesheet,表示给页面引入样式表,type固定为text/css
    rel=“stylesheet” type=“text/css” href=“css文件的链接或者路径”

    DOCTYPE html>
    <html>
    <head>
    	<meta charset="utf-8">
    	<title>title>
    	
    	<style>
    		/* 这是CSS注释 */
    		h1 {
    			color: purple;
    		}
    	style>
    	
    	<link rel="stylesheet" type="text/css" href="css/样式.css" />
    head>
    
    <body style="background-color: antiquewhite;">
    	<h1>这里是h1标签h1>
    body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    CSS选择器

    1. 通配符选择器。:* :能改变所有标签的样式。
    2. 标签选择器。 标签名 :不加限定条件,能够修改页面中所有某标签。
    3. id选择器。#设置的标签名{}
    4. class选择器。.设置的标签名
    5. 父子选择器。父标签 > 子标签:最终选择修改的是子标签。
    6. 后代选择器。祖先标签 后代标签:最终选择修改的是后代标签。
    7. 兄弟选择器。 长兄标签 ~ 弟弟标签。
    8. 相邻兄弟选择器。 刘关张:刘 + 关 关 + 张。
    9. nth-child选择器。 a:nth-child(数字) ->找div标签下第二个a标签(html下标从1开始)(数字=3:找第几个标签,如果发现一致,就选择,如果不一致,就都不选择)。
    DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title>title>
    		<style>
    			#one{}
    	style>
    head>
    <body id="one">
    	<div>
    		<a href="">a>
    	div>
    body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    CSS文字常用属性:

    color:修改文字颜色

    font-size:字体尺寸

    font-family:字体

    text-align:位置(left、right、center)

    text-decoration:在文字的下方或者上方或中间添加一条横线

    DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title>title>
    		<style>
    			/* 所有选择器可以组合使用 */
    			/* 标签选择器 */
    			/* 将页面中所有的div改为某样式 */
    			/* div {
    				border: 1px dotted black;
    				width: 100px;
    				height: 100px;
    			} */
    			/* 将body标签的子标签中第一个div标签改为某样式 */
    			body>div:nth-child(1) {
    				border-top: 1px dotted black;
    				border-bottom: 1px solid red;
    				border-left: 1px dashed blue;
    				border-right: 5px double green;
    				width: 100px;
    				height: 100px;
    				/*表示修改四个角 */
    				border-radius: 100% 50%;
    			}
    		#one {
    			border-top: 5px solid yellowgreen;
    			width: 100px;
    			height: 200px;
    			background-color: antiquewhite;
    
    		}
    
    		.one {
    
    			border: 3px double blue;
    			border-radius: 100%;
    		}
    
    		p {
    			/* color: red; */
    			/* color: #ff0000; */
    			/* color: rgb(255, 0, 0); */
    			color: rgba(255, 0, 0, 0.5);
    			text-align: center;
    			font-size: 50px;
    			/* 下划线 */
    			/* text-decoration: underline; */
    			/* 上划线 */
    			/* text-decoration: overline; */
    			/* 从文字中间穿过 */
    			text-decoration: line-through;
    		}
    	style>
    head>
    <body>
    	<div>div>
    	<div id="one">div>
    	<div class="one">
    		<div id="one">div>
    	div>
    	<p><b>今日安排b>p>
    	<ul>
    		<li>上课li>
    		<li>上课li>
    		<li>上课li>
    		<li>上课li>
    	ul>
    body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
  • 相关阅读:
    JetLinks设备接入的认识与理解【woodwhales.cn】
    Solon 1.6.36 发布,更现代感的应用开发框架
    NumPy 均匀分布模拟及 Seaborn 可视化教程
    java毕业设计车险销售管理系统mybatis+源码+调试部署+系统+数据库+lw
    QT学习day5(QT实现TCP协议)
    Java之juc旅途-Executor(四)
    因果推断三种分析框架
    java毕业设计球迷信息交流论坛源码+lw文档+mybatis+系统+mysql数据库+调试
    IDEA 官宣全新默认 UI,真香
    开源模型应用落地-FastAPI-助力模型交互-WebSocket篇(三)
  • 原文地址:https://blog.csdn.net/qq_56630044/article/details/126292957