Nintendo Switch 新闻爬虫 #362
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Nintendo Switch 新闻爬虫 | |
| on: | |
| schedule: | |
| - cron: '0 9 * * *' # 每天早上 9 点执行(UTC 时间) | |
| workflow_dispatch: # 支持手动触发 | |
| jobs: | |
| crawl-and-update: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| # 1. 检出代码 | |
| - name: 检出仓库 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # 2. 设置 Python 环境 | |
| - name: 设置 Python 3.10 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| # 3. 安装系统依赖 | |
| - name: 安装系统依赖 | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxrender1 \ | |
| libxext6 \ | |
| xvfb \ | |
| libasound2 \ | |
| libffi7 \ | |
| libx264-163 \ | |
| jq | |
| sudo apt-get clean | |
| # 4. 安装 Python 依赖 | |
| - name: 安装 Python 包 | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install playwright beautifulsoup4 pytz | |
| pip install -r requirements.txt | |
| # 5. 安装 Playwright 浏览器 | |
| - name: 安装 Chromium | |
| run: | | |
| python -m playwright install chromium | |
| python -m playwright install-deps | |
| # 6. 运行爬虫 | |
| - name: 执行爬虫脚本 | |
| run: python crawler.py | |
| # 7. 调试输出 | |
| - name: 显示生成内容 | |
| run: | | |
| echo "=== 最新新闻 ===" | |
| cat results/switch_news_latest.md | |
| echo "\n=== JSON 数据 ===" | |
| jq . results/results_latest.json 2>/dev/null || echo "JSON解析失败" | |
| # 8. 提交变更 | |
| - name: 自动提交更新 | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| # 添加新生成的文件 | |
| git add results/ | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git commit -m "自动更新: $(date +'%Y-%m-%d %H:%M')" | |
| git push origin HEAD:main | |
| echo "变更已提交" | |
| else | |
| echo "无新内容需要更新" | |
| fi |