
#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')"

```