Python入门自学进阶-Web框架——35、网络爬虫使用

2023-05-16

自动从网上抓取信息,就是获取相应的网页,对网页内容进行抽取整理,获取有用的信息,保存下来。

要实现网上爬取信息,关键是模拟浏览器动作,实现自动向网址发送请求,然后获取到相应的信息流,在对这个信息流进行统计查找,得到想要的信息。

Requests第三方库是基于Python开发的HTTP 库,其在Python内置模块(Python标准库中提供了:urllib、urllib2、httplib等模块以供Http请求,可用性不太好)的基础上进行了高度的封装,从而使得Pythoner进行网络请求时,变得美好了许多,使用Requests可以轻而易举的完成浏览器可有的任何操作。

一、requests模块

安装 pip3 install requests

二、requests模块的方法

requests 方法如下表:

方法

描述

delete(url, args)

发送 DELETE 请求到指定 url

get(url, params, args)

发送 GET 请求到指定 url

head(url, args)

发送 HEAD 请求到指定 url

patch(url, data, args)

发送 PATCH 请求到指定 url

post(url, data, json, args)

发送 POST 请求到指定 url

put(url, data, args)

发送 PUT 请求到指定 url

request(method, url, args)

向指定的 url 发送指定的请求方法

  • url 请求 url。

  • data 参数为post方法要发送到指定 url 的字典、元组列表、字节或文件对象。

  • json 参数为要发送到指定 url 的 JSON 对象。

  • args 为其他参数,比如 cookies、headers、verify等。

  • params参数为get方法要发送到指定 url 的参数键值对

对于GET方法,参数是params,最终会被组合到url中,以?key1=value1&key2=value2形式提交,对于POST方法,参数是data,不在url中体现,在请求体中保存。

三、GET请求

import requests

ret = requests.get('https://www.sina.com/') # 无参数
ret.encoding = 'utf-8'  # 如果不写这一句,打印的中文乱码
print(ret.url)   # 响应的地址
print(ret.text)  # 返回的页面内容

url是https://www.sina.com/

返回的是一个response对象,该对象包含了具体的响应信息。

属性或方法

说明

apparent_encoding

编码方式

close()

关闭与服务器的连接

content

返回响应的内容,以字节为单位

cookies

返回一个 CookieJar 对象,包含了从服务器发回的 cookie

elapsed

返回一个 timedelta 对象,包含了从发送请求到响应到达之间经过的时间量,可以用于测试响应速度。比如 r.elapsed.microseconds 表示响应到达需要多少微秒。

encoding

解码 r.text 的编码方式

headers

返回响应头,字典格式

history

返回包含请求历史的响应对象列表(url)

is_permanent_redirect

如果响应是永久重定向的 url,则返回 True,否则返回 False

is_redirect

如果响应被重定向,则返回 True,否则返回 False

iter_content()

迭代响应

iter_lines()

迭代响应的行

json()

返回结果的 JSON 对象 (结果需要以 JSON 格式编写的,否则会引发错误)

links

返回响应的解析头链接

next

返回重定向链中下一个请求的 PreparedRequest 对象

ok

检查 "status_code" 的值,如果小于400,则返回 True,如果不小于 400,则返回 False

raise_for_status()

如果发生错误,方法返回一个 HTTPError 对象

reason

响应状态的描述,比如 "Not Found" 或 "OK"

request

返回请求此响应的请求对象

status_code

返回 http 的状态码,比如 404 和 200(200 是 OK,404 是 Not Found)

text

返回响应的内容,unicode 类型数据

url

返回响应的 URL

import requests

payload = {'key1':'value1','key2':'value2'}
ret = requests.get('https://www.sina.com/',params=payload) # 带参数
ret.encoding='utf-8'
print(ret.url)
print(ret.text)

url是https://www.sina.com/?key1=value1&key2=value2

四、POST请求

payload1 = {'key1':'value1','key2':'value2'}
ret = requests.post('http://www.sina.com',data=payload1)  #基本POST
print(ret.text)

#发送请求头和数据
import json
url = "https://www.sina.com"
payload1 = {'key1':'value1','key2':'value2'}
headers = {'content-type':'application/json'}
ret = requests.post(url,data=json.dumps(payload1),headers=headers)
print(ret.text)

使用post方法,需要会使用调试工具,使用网络来查看其传递的参数,如登录百度:在post提交的参数中有username和password参数。

五、request方法

payload = {'key1':'value1','key2':'value2'}
url = "https://www.sina.com"
ret = requests.request(method='get',url=url,params=payload)
print(ret.url)
print(ret.text)

其他如get、post等方法,是对request方法的再包装。

六、关于request方法的参数——通过源代码查看

在查看request的源代码,提供了参数的解释:

"""Constructs and sends a :class:`Request <Request>`.

:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.

:param url: URL for the new :class:`Request` object.

:param params: (optional) Dictionary, list of tuples or bytes to send

in the query string for the :class:`Request`.

:param data: (optional) Dictionary, list of tuples, bytes, or file-like

object to send in the body of the :class:`Request`.

:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.

:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.

:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.

:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.

``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``

or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string

defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers

to add for the file.

:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.

:param timeout: (optional) How many seconds to wait for the server to send data

before giving up, as a float, or a :ref:`(connect timeout, read

timeout) <timeouts>` tuple.

:type timeout: float or tuple

:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.

:type allow_redirects: bool

:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.

:param verify: (optional) Either a boolean, in which case it controls whether we verify

the server's TLS certificate, or a string, in which case it must be a path

to a CA bundle to use. Defaults to ``True``.

:param stream: (optional) if ``False``, the response content will be immediately downloaded.

:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.

:return: :class:`Response <Response>` object

:rtype: requests.Response

Usage::

>>> import requests

>>> req = requests.request('GET', 'https://httpbin.org/get')

>>> req

<Response [200]>

"""

request方法中关于post或get的参数传递

# filename:s1.py
import requests
requests.request(
    method='get', # 或 'post'
    url='http://127.0.0.1:8000/test/',
    params={'key1':'value1','key2':'value2'},
    # params最终拼接形成get的url参数部分,也可以是如下形式: “key1=value1&key2=value2”
    data = {'user':'root','pwd':'123456'}, # 此格式默认发送content-type:application/X-WWW-form-urlencoding
    # data是post方法提交时的参数,在请求体中传递;也可如下形式:"user=root;pwd=123456"
)

view函数test:

def test(request):
    print(request.GET)
    print(request.POST)
    print(request.body)
    return HttpResponse("..........................")

URLconf:path('test/',views.test,name='test'),

运行s1.py,结果,可以看出,POST中无内容,但是body中有内容,即data作为参数在请求体中保存传递,虽然是get请求,但是data内容也传递了。

将s1.py中的method改为post,结果

首先,post请求,params参数也传递了,而request.POST中的内容,是从body中内容解析出来的,只有当content-type是 'application/x-www-form-urlencoded',Django才会从body中将内容解析成字典给POST。当data是字典形式时,默认发送了content-type = 'application/x-www-form-urlencoded',在test.py中加上:print(request.headers):

运行的结果如下:
<QueryDict: {'key1': ['value1'], 'key2': ['value2']}>
<QueryDict: {'user': ['root'], 'pwd': ['123456']}>
b'user=root&pwd=123456'
{'Content-Length': '20', 'Content-Type': 'application/x-www-form-urlencoded', 'Host': '127.0.0.1:8000', 'User-Agent': 'python-requests/2.28.2', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}

当使用data = 'user=root;pwd=123456'时,打印的POST是空的,如下图

此时的content-type默认是text/plain,设置headers:

此时运行POST有数据了。

传递数据还可以使用json:

requests.request(
    method='post', # 或 'post'
    url='http://127.0.0.1:8000/test/',
    # params={'key1':'value1','key2':'value2'},
    params = "key1=value1&key2=value2",
    # params最终拼接形成get的url参数部分,也可以是如下形式: “key1=value1&key2=value2”
     json = json.dumps({'user':'root','pwd':'123456'}), # 此时要使用application/json
)

运行结果:

此时body中是json格式字符串,POST中无内容,content-type是application/json

参数:headers和cookies

有时会发生以下情形:在浏览器中可以访问页面,但是使用request方法却无法获取,原因一般如下:

一是headers中没有加User-Agent;二是没有Referer;三是对于需要登录的页面,需要设置cookie参数。

User-Agent,对于谷歌浏览器,一般是“Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36',”格式;

Referer指出是从哪一个页面过来的,即上一个访问的是哪个页面;

Cookies,通过浏览器的调试工具,获取cookie,将其中的重要内容作为cookies的内容

res = requests.get(
    # url='https://i.csdn.net/#/user-center/profile?spm=1010.2135.3001.5111',
    url = 'https://blog.csdn.net/kaoa000/',
    headers = {
        'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.36',
        # 'Referer':'https://www.zhihu.com/',
    },

    cookies ={'UserName':'kaoa000',
              'UserInfo':'xxx获取的内容',
              'UserToken':'调试工具获取的内容',
              'UserNick':'调试工具获取的cookie的内容',
              'UN':'调试工具获取的cookie的内容',
              'p_uid':'调试工具获取的cookie的内容',
              'csrfToken':'调试工具获取的cookie的内容',
              'dc_sid':'调试工具获取的cookie的内容',
              'SESSION':'调试工具获取的cookie的内容',
    }
)
print(res.text)

发送文件

def param_files():
    # 发送文件
    file_dict = {
    'f1': open('readme', 'rb')
    }
    requests.request(method='POST',
    url='http://127.0.0.1:8000/test/',
    files=file_dict)

    # 发送文件,定制文件名
    file_dict = {
    'f1': ('test.txt', open('readme', 'rb'))
    }
    requests.request(method='POST',
    url='http://127.0.0.1:8000/test/',
    files=file_dict)

    # 发送文件,定制文件名
    file_dict = {
    'f1': ('test.txt', "hahsfaksfa9kasdjflaksdjf")
    }
    requests.request(method='POST',
    url='http://127.0.0.1:8000/test/',
    files=file_dict)

    # 发送文件,定制文件名
    file_dict = {
        'f1': ('test.txt', "hahsfaksfa9kasdjflaksdjf", 'application/text', {'k1': '0'})
    }
    requests.request(method='POST',
                     url='http://127.0.0.1:8000/test/',
                     files=file_dict)

登录认证:只针对基本的登录认证

需要使用HTTPBasicAuth类

def param_auth():
    from requests.auth import HTTPBasicAuth, HTTPDigestAuth
    import requests

    ret = requests.get('https://api.github.com/user', auth=HTTPBasicAuth('wupeiqi', 'sdfasdfasdf'))
    print(ret.text)

    # ret = requests.get('http://192.168.1.1',
    # auth=HTTPBasicAuth('admin', 'admin'))
    # ret.encoding = 'gbk'
    # print(ret.text)

    # ret = requests.get('http://httpbin.org/digest-auth/auth/user/pass', auth=HTTPDigestAuth('user', 'pass'))
    # print(ret)

关键是给HTTPBasicAuth()传递两个参数:用户名和密码,然后以auth变量名传递过去。

超时设置:

def param_timeout():
    # ret = requests.get('http://google.com/', timeout=1)
    # print(ret)

    # ret = requests.get('http://google.com/', timeout=(5, 1))  
    # 第一个参数5是请求时的超时时间,即点击链接后的等待时间,第二个参数是读取数据的时间,即请求完成,开始读取数据的时间
    # print(ret)

重定向设置:

def param_allow_redirects():
    ret = requests.get('http://127.0.0.1:8000/test/', allow_redirects=False)
    print(ret.text)

代理设置

def param_proxies():
    # proxies = {
    # "http": "61.172.249.96:80",
    # "https": "http://61.185.219.126:3128",
    # “https://www.baidu.com”:"61.172.249.96:80"  # 访问某个网站使用代理
    # }

    # proxies = {'http://10.20.1.128': 'http://10.10.1.10:5323'}

    # ret = requests.get("http://www.proxy360.cn/Proxy", proxies=proxies)
    # print(ret.headers)

    # 当代理需要登录验证时,如下
    # from requests.auth import HTTPProxyAuth  
    #
    # proxyDict = {
    # 'http': '77.75.105.165',
    # 'https': '77.75.105.165'
    # }
    # auth = HTTPProxyAuth('username', 'mypassword')
    #
    # r = requests.get("http://www.google.com", proxies=proxyDict, auth=auth)
    # print(r.text)

证书验证:

需要携带证书,使用cert,使用内置证书,使用verify

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python入门自学进阶-Web框架——35、网络爬虫使用 的相关文章

  • setTimeout()和setInterval()详解

    JavaScript是单线程语言 xff0c 但是它可以通过设置超时值和间歇时间值来指定代码在特定的时刻执行 超时值是指在指定时间之后执行代码 xff0c 间歇时间值是指每隔指定的时间就执行一次代码 超时调用 超时调用使用window对象的
  • Centos 7.6安装Xfce+VNC Server

    Centos 7 6安装Xfce 43 VNC Server 工作环境安装xface安装 VNC Server在云服务器控制台中设置安全组规则使用VNC Viewer连接云服务器 工作环境 华为云服务器 操作系统 xff1a CentOS
  • C++和C语言的区别是什么?

    首先C 43 43 和C语言本来就是两种不同的编程语言 xff0c 但C 43 43 确实是对C语言的扩充和延伸 xff0c 并且对C语言提供后向兼容的能力 C 43 43 这个词在中国大陆的程序员圈子中通常被读做 C加加 xff0c 而西
  • ubuntu18.0.4安装pip3及虚拟环境virtualenv详细教程

    1 ubuntu安装pip3 该命令是修复安装及补全那些缺少的软件 xff1a sudo apt get f install 安装pip3 xff1a sudo apt get install python3 pip升级pip3 xff1a
  • 什么是子网掩码,如何判断两个IP是不是同一网段

    1 xff1a 什么是子网掩码 xff1f 子网掩码不能单独存在 xff0c 它必须结合IP地址一起使用 子网掩码只有一个作用 xff0c 就是将某个IP地址划分成网络地址和主机地址两部分 说的通俗的话 xff0c 就是用来分割子网和区分那
  • 利用esp-8266实现wifi攻击

    0x00 前言 之前在b站上看到这个wifi模块的攻击视频感觉挺有意思 xff0c 就在某宝上入了一个拿回来玩玩 0x01 外观 转接头需要自己另外买 0x03 编译程序 https anky cc esp8266 deauther wif
  • 如何从 JavaScript 对象中删除属性?

    问题描述 xff1a 给定一个对象 xff1a let myObject span class token operator 61 span span class token punctuation span span class toke
  • 在 Git 中推送提交时消息“src refspec master does not match any”

    问 xff1a 我克隆我的存储库 xff1a git clone ssh span class token operator span span class token operator span span class token oper
  • Qt编译、链接和运行参数的设置

    Qt编译 链接和运行参数的设置 Qt笔记 使用 Qt Creator 集成开发环境构建和运行程序是一件非常简单的事情 xff0c 一个按钮或者一个快捷键搞定全部 xff0c 通过 Qt Creator使用教程 xff08 简明版 xff09
  • 常用Linux命令行技巧

    结果以表格形式输出 column t 比如 xff1b span class token function mount span span class token operator span column t 默认分隔符为空格 xff0c
  • CV往哪卷?李飞飞指出三颗「北极星」:具身智能,视觉推理和场景理解

    点击下方卡片 xff0c 关注 CVer 公众号 AI CV重磅干货 xff0c 第一时间送达 转载自 xff1a 新智元 编辑 xff1a LRS 导读 ImageNet见证了计算机视觉发展的辉煌历程 xff0c 在部分任务性能已超越人类
  • Java异常处理的九个最佳实践

    1 确保在Finally程序块中完成资源释放或者使用Try With语句 比如对于InputStream xff0c 当我们使用完毕 xff0c 我们要确保资源被正确关闭 xff0c 比如下面我们常见的错误用法 xff0c 不要在try模块
  • CodeMirror使用笔记

    最近因工作需要 xff0c 在项目中使用了CodeMirror代码编辑器 xff0c 以下是使用笔记 首先 xff0c 看下最终的效果 引入基本的需要资源 lt script src 61 34 lt 61 request getConte
  • JAVA注解

    Java注解Annotations主要用于为目标程序提供额外补充的说明信息 注解以 64 符号标识注解并不改变编译程序的行为注意可以为程序元素 xff1a 实例变量 构造方法 方法或者类添加元数据信息注解并不是单纯的注释 xff0c 但却可
  • ubuntu中GitLab的安装与配置

    这里 xff0c 我们采用离线安装的方式安装GitLab 首先 xff0c 我们从清华大学开源软件镜像站中下载软件包 xff0c 用户可根据实际的服务器操作系统版本来选择不同的镜像资源 xff0c 这里我们以ubuntu为例 执行命令sud
  • Jenkins使用笔记

    本章简单记录Jenkins的使用笔记 首先 xff0c 我们从官网中下载安装介质 xff0c 可以看到这里有适合各种操作系统版本的安装源介质 xff0c 简单起见 xff0c 我们直接下载一个通用的war程序包 执行命令java jar j
  • GitLab 与 Jenkins 持续集成实践

    首先 xff0c 我们简单说明下我们的部署环境 xff1a GitLab xff1a 192 168 43 61 Jenkins xff1a 192 168 43 116 Jenkins中系统设置中 xff0c 配置GitLab连接信息 x
  • Linux下免密认证登录失败原因总结

    事件背景 A机器已经生产rsa密钥且已经将public key添加到B机器 root ssh authorized keys xff0c 但是从A机器上ssh root 64 B机器时仍然需要输入密码 xff0c 即无密码认证失败 原因总结
  • 公钥添加到authorized_keys到文件中之后仍无法免密登陆

    接上一章 xff0c 关于Linux下免密登陆失败 xff0c 这里找了Stackoverflow上关于这个问题的讨论 xff1a Adding public key to ssh authorized keys does not log
  • Java 8 中的List排序

    按字母顺序排序字符串列表 List lt String gt cities 61 Arrays asList 34 Milan 34 34 london 34 34 San Francisco 34 34 Tokyo 34 34 New D

随机推荐

  • Microservices vs SOA - 微服务与SOA

    开始之前 xff0c 我们先简单看下单体架构 SOA与微服务之间的区别 xff0c 如下图所示 xff1a 简单来讲 xff0c 对于单体架构 xff0c 其就像一个超大容器 xff0c 容器内集中包含了该应用的所有软件组件 xff0c 并
  • Python 机器学习8:sklearn 聚类算法

    1 K Means算法是一种广泛使用的聚类算法 from sklearn cluster import KMeans K Means是聚焦于相似的无监督的算法 xff0c 以距离作为数据对象间相似性度量的标准 xff0c 即数据对象间的距离
  • 什么是微服务——微服务架构体系介绍

    Why Microservices 回答这个问题前 xff0c 我们先看下之前大行其道的单体架构 Monolithic Architecture xff0c 对于非专业人士来讲 xff0c 所谓的单体架构 xff0c 其就像一个超大容器 x
  • 微服务架构特征

    一个典型的微服务架构 xff08 MSA xff09 通常包含以下组件 xff1a 客户端 xff1a 微服务架构着眼于识别各种不同的类型的设备 xff0c 以及在此设备上进行的各种管理操作 xff1a 搜索 构建 配置等等身份标识提供者
  • 微服务架构系列——API服务网关

    本章我们简单介绍微服务架构下的API服务网关 xff0c 本章我们将讨论以下话题 xff1a 什么是API服务网关为什么需要API服务网关API服务网关的工作机制 处理横切关注点 当我们在开发设计大型软件应用时 xff0c 我们一般都会采用
  • Java之keytool命令学习

    Java Keytool is a key and certificate management utility It allows users to manage their own public private key pairs an
  • HashMap 与 HashTable的区别

    HashMap 实现了Map接口非线程同步 xff0c 非线程安全不允许重复键键和值均允许为null HashMap lt Interger String gt employeeHashmap 61 new HashMap lt Integ
  • 如何避免敏捷失败?

    很多人都听说敏捷 xff0c 有些人知道敏捷是什么 xff0c 有些人也尝试过敏捷 xff0c 本章中将列举出一些常见的错误敏捷实践 xff0c 如果想要避免敏捷失败 xff0c 建议还是要对照下你所在的敏捷团队中有没有类似的敏捷实践 xf
  • 一个人有文化,到底有多重要?

    关于什么是文化 xff0c 我最最欣赏的回答 xff0c 是作家梁晓声的四句概括 xff1a 根植于内心的修养 xff0c 无需提醒的自觉 xff0c 以约束为前提的自由 xff0c 为别人着想的善良 01 一位叫做 Judy 的空姐 xf
  • MyBatis动态SQL中Map参数处理

    在MyBatis中 xff0c 如果我们需要传递两个参数 xff0c 有一种方式是通过Map作为传入参数 xff0c 在动态SQL中 xff0c 我们需要对传入的Map参数中的值进行判断 xff0c 然后进行动态SQL的条件拼接处理 假设我
  • MyBatis框架下防止SQL注入

    与传统的ORM框架不同 xff0c MyBatis使用XML描述符将对象映射到SQL语句或者存储过程中 xff0c 这种机制可以让我们更大的灵活度通过SQL来操作数据库对象 xff0c 因此 xff0c 我们必须小心这种便利下SQL注入的可
  • 使用android 视频解码mediaCodec碰到的几个问题

    问题1 mediaCodec dequeueInputBuffer一直返回 1 xff0c APP现象 xff1a 视屏卡屏 原因 xff1a 这是因为inputbuffer的内容有误 xff0c 导致无法解码 可通过设延时时间解决 xff
  • 云计算思维导图

    根据近期的云计算学习心得 xff0c 将云计算部分内容制作成思维导图 xff0c 方便于广大云计算学习者作为辅导讲义 xff01 思维导图内容主要包含 xff1a 1 云计算概述 2 云体系结构 3 网络资源 4 存储资源 5 硬件介绍 6
  • 路由器重温——串行链路链路层协议积累

    对于广域网接口来说 xff0c 主要的不同或者说主要的复杂性在于理解不同接口的物理特性以及链路层协议 xff0c 再上层基本都是 IP 协议 xff0c 基本上都是相同的 WAN口中的serial接口主要使用点对点的链路层协议有 xff0c
  • 路由器重温——PPPoE配置管理-2

    四 配置设备作为PPPoE服务器 路由器的PPPoE服务器功能可以配置在物理以太网接口或 PON 接口上 xff0c 也可配置在由 ADSL 接口生成的虚拟以太网接口上 1 配置虚拟模板接口 虚拟模板接口VT和以太网接口或PON接口绑定后
  • Python入门自学进阶——1--装饰器

    理解装饰器 xff0c 先要理解函数和高阶函数 首先要明白 xff0c 函数名就是一个变量 xff0c 如下图 xff0c 定义一个变量名和定义一个函数 xff0c 函数名与变量名是等价的 既然函数名就是一个变量名 xff0c 那么在定义函
  • Python入门自学进阶-Web框架——21、DjangoAdmin项目应用

    客户关系管理 以admin项目为基础 xff0c 扩展自己的项目 一 创建项目 二 配置数据库 xff0c 使用mysql数据库 xff1a 需要安全mysqlclient模块 xff1a pip install mysqlclient D
  • Python入门自学进阶-Web框架——33、瀑布流布局与组合查询

    一 瀑布流 xff0c 是指页面布局中 xff0c 在显示很多图片时 xff0c 图片及文字大小不相同 xff0c 导致页面排版不美观 如上图 xff0c 右边的布局 xff0c 因为第一行第一张图片过长 xff0c 第二行的第一张被挤到第
  • Python入门自学进阶-Web框架——34、富文本编辑器KindEditor、爬虫初步

    KindEditor 是一个轻量级的富文本编辑器 xff0c 应用于浏览器客户端 一 首先是下载 xff1a http kindeditor net down php xff0c 如下图 下载后是 解压缩后 xff1a 红框选中的都可以删除
  • Python入门自学进阶-Web框架——35、网络爬虫使用

    自动从网上抓取信息 xff0c 就是获取相应的网页 xff0c 对网页内容进行抽取整理 xff0c 获取有用的信息 xff0c 保存下来 要实现网上爬取信息 xff0c 关键是模拟浏览器动作 xff0c 实现自动向网址发送请求 xff0c