2-3-01模块-定义

模块

1. 定义

集成了很多功能的函数集合

2. 分类

  • 内置模块,Python内部帮助我们提供好的。
  • 第三方模块,网上下载别人写好的模块(功能集合)
  • 自定义模块:把相同的函数放入一个模块中

3. 内置模块

1. requests-下载

根据URL下载图片/视频

import requests

res = requests.get(
    url="https://f.video.weibocdn.com/000pTZJLgx07IQgaH7HW010412066BJV0E030.mp4?label=mp4_720p&template=1280x720.25.0&trans_finger=1f0da16358befad33323e3a1b7f95fc9&media_id=4583105541898354&tp=8x8A3El:YTkl0eM8&us=0&ori=1&bf=2&ot=h&ps=3lckmu&uid=3ZoTIp&ab=3915-g1,966-g1,3370-g1,3601-g0,3601-g0,3601-g0,1493-g0,1192-g0,1191-g0,1258-g0&Expires=1608204895&ssig=NdYpDIEXSS&KID=unistore,video",
    headers={
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
    }
)

2. os - 判断是否存在

# 判断images文件夹是否存在
import os
os.path.exists("images")

3. configparser - 处理ini格式文件

import configparser
config = configparser.ConfigeParser() # configparser.ConfigeParser()   固定搭配
config.read('my.conf',encoding='utf-8')   #读取这个my.conf配置文件
result = config.sections()  # config.sections() 获取所有的节点
posted @ 2022-10-19 09:44  布丁家的苏苏  Views(4)  Comments(0)    收藏  举报