工作中总有些重复性任务让人头疼:手动整理文件夹、反复填写 Excel、盯着商品价格变动……用 Python 写几个小脚本,就能把时间省下来。这里分享几个我实际用过的自动化场景,代码可以直接拿来改。
下载简历模板
有些网站会公开分享设计不错的简历模板,一个个手动另存太麻烦。用 requests + BeautifulSoup 写个脚本,就能批量抓回来。
import requests
from bs4 import BeautifulSoup
import os
def download_resume_templates(url):
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
# 假设所有包含 .pdf 后缀的链接都是简历模板
resume_links = [a['href'] for a in soup.find_all('a', href=True) if '.pdf' in a['href']]
if not os.path.exists('templates'):
os.makedirs('templates')
for link in resume_links[:10]: # 仅演示前 10 个
try:
file_url = f"https://example.com{link}"
r = requests.get(file_url, headers=headers)
filename = link.split('/')[-1]
with open(f'templates/{filename}', 'wb') as f:
f.write(r.content)
print()
Exception e:
()


