10、常用正则表达式
匹配网址
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
匹配手机号
(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}
匹配中文
[\u4e00-\u9fa5]
11、修改Python镜像
pip3 config set global.index-url https://repo.huaweicloud.com/repository/pypi/simple pip3 config list pip3 install --upgrade pip
需要下载的包【pip3 install requests】
demo示例:
import requests import re import os from tkinter import * import tkinter.messagebox as messagebox root = Tk() screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() dialog_width = 800 dialog_height = 100 # 前两个参数是窗口的大小,后面两个参数是窗口的位置 root.geometry( "%dx%d+%d+%d" % (dialog_width, dialog_height, (screenwidth - dialog_width) / 2, (screenheight - dialog_height) / 2)) root.title("去水印下载工具(红目香薰提供):") Label(root, text='url:').grid(row=0, column=0) e = Entry(root, width=90) e.grid(row=0, column=3, padx=10, pady=5) root.resizable(height=False, width=False) def show(): try: oldUrl = e.get() headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" } short_url = re.findall('(http[|s]?://[^\s]*/)', oldUrl)[0] url = requests.get(url=short_url, headers=headers).url item_id = url.split('/')[4][0:19] url = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={0}".format(item_id) html = requests.get(url, headers=headers) title = html.json()['item_list'][0]['desc'] # 抖音视频的文案内容 print(title) video_id = html.json()['item_list'][0]['video']['play_addr']['uri'] # 视频的uri,也就是video_id video_url = f'https://aweme.snssdk.com/aweme/v1/play/?video_id={video_id}&ratio=720p&line=0' mp4 = requests.get(video_url, headers=headers).content # 开始下载 saveUrl = r"{0}.mp4".format(title) file = open(saveUrl, "wb+") file.write(mp4) file.close() os.system("explorer .") messagebox.showinfo("提示", "{0}下载完毕!".format(title)) except: messagebox.showinfo("提示", "错误路径") Button(root, text='下载视频', width=10, command=show) \ .grid(row=3, column=0, sticky=W, padx=10, pady=5) mainloop()
bat文件也一样需要创建成一个bat文件,方便直接使用。
python GetDownRain.py
下载示例
12、Redis常用命令
清空缓存flushall
添加有效时间expire key seconds
redis事务
multi:用来标记一个事务的开始
exec:用来执行一组已压入的队列