随笔分类 - python
1
摘要:import pymysql config = { 'host': '127.0.0.1', 'port': 3306, 'user': 'root', 'password': 'root', 'database': 'sys', 'cursorclass': pymysql.cursors.Dic
阅读全文
摘要:import re stringA = "abcdefghijk" pattern = re.compile(r'd(.+?)h') # 匹配d和h中间的内容 print(re.findall(pattern, stringA)) # ['efg'] stringB = "abcdefg(pytho
阅读全文
摘要:import requests url = "https://***" payload={} proxies = {"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"} headers = { 'Cookie': 'Co
阅读全文
摘要:import json from websocket._core import create_connection # 安装 websocket-client host = "wss://****" ws = create_connection(host,timeout=3) try: # 发送da
阅读全文
摘要:import time # 时间戳转日期 timeStamp = 1656399821 # 十位时间戳 timeArray = time.localtime(timeStamp) printDate = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) pr
阅读全文
摘要:import random import string tempId = ''.join(random.sample(string.digits, 11)) print(tempId) 报错:ValueError: Sample larger than population or is negati
阅读全文
摘要:import random import string print(string.digits) # 数字 print(string.ascii_letters) # 大小写 print(string.ascii_lowercase) # 小写 print(string.ascii_uppercas
阅读全文
摘要:回退selenium版本 pip install selenium==3.141.0
阅读全文
摘要:import datetime today = datetime.date.today() # 周一为第一天 week_start = today - datetime.timedelta(days=today.weekday()) week_end = today + datetime.timed
阅读全文
摘要:import datetime stamp = datetime.datetime(2021,9,1,15,23,56) print("%Y 4位数年:",stamp.strftime("%Y")) # %Y 4位数年: 2021 print("%y 2位数年:",stamp.strftime("%
阅读全文
摘要:import datetime datetime.date(2021,12,1) # 2021-12-01 datetime.time(12,23,48,333) # 12:23:48.000333 datetime.datetime(2021,12,1,12,23,48,333) # 2021-1
阅读全文
摘要:a = {"A":"1"} b = a b.update({"B":"2"}) print("a",a) print("b",b) '''用=时,修改b时,原字典a被修改 a {'A': '1', 'B': '2'} b {'A': '1', 'B': '2'} ''' a = {"A&quo
阅读全文
摘要:import base64 str_A = "待加密的字符串AABBCC" eStr_A = base64.b64encode(str_A.encode()) print(eStr_A) # b'5b6F5Yqg5a+G55qE5a2X56ym5LiyQUFCQkND' dStr_A = base6
阅读全文
摘要:base64.b64decode(str_A) 把$替换成+ str_A.replace("$","+") base64.b64decode(str_A)
阅读全文
摘要:import openpyxl list_wb = openpyxl.load_workbook('list.xlsx') #打开现有工作表 sheet = list_wb.active print(sheet.max_row) # 获取最大行 print(sheet.max_column) # 获
阅读全文
摘要:import xlrd from xlutils.copy import copy # 打开Excel wb = xlrd.open_workbook('list.xls') # 打开Excel的sheet,有多种方式,此处选择第一个sheet sheet = wb.sheet_by_index(0
阅读全文
摘要:from PIL import Image left = 763 top = 863 right = 1258 bottom = 962 im = Image.open("img.jpg") im = im.crop((left, top, right, bottom)) im.save("img_
阅读全文
摘要:import requests pic_url = "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" r = requests.get(pic_url) with open("1.png", "wb")as f
阅读全文
摘要:import optparse def testparam(paramA,paramB,paramC='C'): print('paramA:', paramA) print('paramB:', paramB) print('paramC:', paramC) def main(): parser
阅读全文
摘要:1、先安装pyinstaller pip install pyinstaller 2、切换到文件目录 cd mypath 3、使用以下命令 pyinstaller -F ***.py
阅读全文
1