Files
nexus/raw/AI/Scrapy + Playwright 抓取TikTok Shop Data.md
2026-04-28 20:03:11 +08:00

89 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: ⚠️ 你使用 Docker可能需要在 Dockerfile 里加入以下内容
source:
author: shenwei
published:
created:
description:
tags: [playwright, scrapy]
---
#scrapy #playwright
## **最推荐:创建虚拟环境 (venv) 并安装 Scrapy + Playwright**
进入你的工程目录:
``` bash
cd ~/Docker/tiktok_shop_scraper
```
创建 venv
``` bash
python3 -m venv venv
```
激活 venv
```
source venv/bin/activate
```
(你会看到终端前面出现 `(venv)`
``` bash
(venv) root@shenwei-HP-ZBook-01:/home/shenwei/Docker/tiktok_shop_scraper#
```
后续再次进入venv
```
source /home/shenwei/Docker/tiktok_shop_scraper/venv/bin/activate
```
在venv环境里安装依赖
``` bash
pip install --upgrade pip
pip install scrapy scrapy-playwright
```
安装 Playwright Chromium
```
playwright install chromium
```
然后运行你的 spider
``` bash
scrapy runspider tiktok_shop_spider.py -a shop_url="https://www.tiktok.com/shop/store/xxxx/xxxxxxxxxxxx"
scrapy runspider tiktok_shop_spider.py -a shop_url="https://www.tiktok.com/shop/store/aopuro/7495894041403296077"
```
---
# ⚠️ 你使用 Docker可能需要在 Dockerfile 里加入以下内容
如果你是用 Dockerfile 构建容器,记得加两行:
```
。/
RUN python3 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH"
```
---
# 🧪 验证 Playwright 是否安装成功
在 venv 中执行:
```
python -c "from playwright.sync_api import sync_playwright; print('Playwright OK')"
```