当前位置:首页>python>Python自动化脚本必学的第三方库

Python自动化脚本必学的第三方库

  • 2026-10-11 08:32:48
Python自动化脚本必学的第三方库

READING

web自动化

  • 自动登录所有账号(再也不怕忘记密码)

  • 定时抓取竞品数据(运营人狂喜)

  • 秒杀限量商品(手速不够代码来凑)

  • Selenium-浏览器自动化

from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysdriver = webdriver.Chrome()  # 需下载对应浏览器驱动driver.get("https://www.google.com")search_box = driver.find_element(By.NAME, "q")search_box.send_keys("Python自动化" + Keys.RETURN)print(driver.title)driver.quit()
  • Requests + BeautifulSoup - 网页抓取

import requestsfrom bs4 import BeautifulSoupurl = "https://example.com"response = requests.get(url)soup = BeautifulSoup(response.text, 'html.parser')titles = [h1.text for h1 in soup.find_all('h1')]  # 提取所有<h1>标签print(titles)

READING

文件与数据处理

  • 3秒合并100个表格(告别复制粘贴) 

  • 自动清洗混乱数据(错误值一键修复) 

  • 每天9点准时发送日报(让邮件自己跑)

  • Pandas - Excel/CSV 处理

import pandas as pd# 读取Excel并处理df = pd.read_excel("data.xlsx")df['New_Column'] = df['Old_Column'] * 2  # 新增列df.to_csv("processed_data.csv", index=False)  # 保存为CSV
  • 批量重命名文件(os+shutil)

import osfolder = "./files"for i, filename in enumerate(os.listdir(folder)):    new_name = f"document_{i}.txt"    os.rename(os.path.join(folder, filename), os.path.join(folder, new_name))

READING

三、GUI自动化

自动整理桌面文件(强迫症福音)  

批量处理图片/视频(自媒体人必备)  

软件自动操作(连PS都能自己P图)

  • PyAutoGUI- 控制鼠标键盘

import pyautoguipyautogui.click(100, 100)    # 点击屏幕坐标(100,100)pyautogui.typewrite("Hello, World!", interval=0.1)   # 模拟打字pyautogui.hotkey('ctrl', 'c')    # 组合键
  • PyWinAuto - 操作Windows应用

from pywinauto import Applicationapp = Application().start("notepad.exe")  # 打开记事本app.Notepad.edit.type_keys("Automation Test")  # 输入文本app.Notepad.menu_select("文件->保存")  # 点击菜单

最新文章

随机文章