You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Web Scraping的eBay智能手表列表采集与参数制表实现

eBay智能手表分类页数据采集实现

采集注意事项

采集平台公开数据需符合对应平台的robots.txt规则与用户协议,建议将请求间隔控制在3秒以上,避免触发反爬机制导致IP被限制。

所需依赖

  • Python 3.8及以上版本
  • 第三方库:requests(发送网络请求)、BeautifulSoup4(解析HTML结构)、pandas(整理数据输出表格)

可通过以下命令安装依赖:

pip install requests beautifulsoup4 pandas

核心采集代码

import time
import requests
from bs4 import BeautifulSoup
import pandas as pd

# 配置请求头模拟浏览器访问
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
}
# 目标分类页地址(对应eBay智能手表分类页)
target_url = "替换为对应分类页地址"
# 存储采集结果的列表
result_list = []

def get_product_info(product_url):
    time.sleep(2)
    resp = requests.get(product_url, headers=headers)
    if resp.status_code != 200:
        return {}
    soup = BeautifulSoup(resp.text, "html.parser")
    # 解析规格参数
    spec_dict = {}
    spec_items = soup.select("div.x-product-specs div.x-spec-section div.x-spec-list-item")
    for item in spec_items:
        key = item.select_one("span.x-spec-name").get_text(strip=True)
        value = item.select_one("span.x-spec-value").get_text(strip=True)
        spec_dict[key] = value
    return spec_dict

# 采集列表页
resp = requests.get(target_url, headers=headers)
soup = BeautifulSoup(resp.text, "html.parser")
product_items = soup.select("ul.b-list__items_nofooter li.s-item")
for item in product_items[:20]: # 默认采集前20条,可自行调整
    product_info = {}
    product_info["产品名称"] = item.select_one("h3.s-item__title").get_text(strip=True)
    product_info["售价"] = item.select_one("span.s-item__price").get_text(strip=True)
    product_info["发货地"] = item.select_one("span.s-item__location").get_text(strip=True) if item.select_one("span.s-item__location") else "未标注"
    product_link = item.select_one("a.s-item__link")["href"]
    # 采集详情页规格
    specs = get_product_info(product_link)
    product_info.update(specs)
    result_list.append(product_info)

# 输出为表格
df = pd.DataFrame(result_list)
# 可选择导出为csv文件
# df.to_csv("ebay智能手表采集结果.csv", index=False, encoding="utf_8_sig")
print(df)

采集结果示例

产品名称售价品牌屏幕尺寸防水等级续航时间发货地
Apple Watch Series 8 GPS 41mm 铝金属表壳$299.99Apple1.57英寸50米18小时美国加利福尼亚
Samsung Galaxy Watch 5 Pro 45mm 蓝牙版$249.99Samsung1.4英寸50米+IP6880小时美国得克萨斯
Fitbit Versa 4 智能运动手表$149.99Fitbit1.58英寸50米6天美国佛罗里达
Amazfit GTS 4 Mini 智能手表$119.99Amazfit1.65英寸50米15天中国香港

内容的提问来源于stack exchange,提问作者shrey patel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 11:27:01