全部
常见问题
产品动态
精选推荐

主流电商平台(淘宝、京东、拼多多、1688、唯品会)商品详情页面的解析示例

管理 管理 编辑 删除


以下是主流电商平台(淘宝、京东、拼多多、1688、唯品会)商品详情页面的解析示例,包含核心字段提取方法和应对策略:

一、淘宝商品详情解析

1. 页面结构特点

  • 动态渲染:部分数据通过 JS 异步加载(如 SKU 信息
  • 防爬机制:频繁请求会触发验证码
  • 数据加密:部分价格信息使用字体加密
  • 注册账号: [注册获取 API 数据](以下是主流电商平台(淘宝、京东、拼多多、1688、唯品会)商品详情页面的解析示例,包含核心字段提取方法和应对策略:

一、淘宝商品详情解析

1. 页面结构特点

  • 动态渲染:部分数据通过 JS 异步加载(如 SKU 信息
  • 防爬机制:频繁请求会触发验证码
  • 数据加密:部分价格信息使用字体加密
  • 注册账号: 注册直接获取 API 数据

2. 核心字段解析

import requests
from bs4 import BeautifulSoup
import re

def parse_taobao_item(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
        'Referer': 'https://www.taobao.com'
    }
    
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 提取商品标题
    title = soup.select_one('h1[data-spm="1000983"]').text.strip()
    
    # 提取价格(处理加密字体)
    price_text = soup.select_one('.tm-price').text
    price = re.search(r'\d+.\d+', price_text).group(0)
    
    # 提取SKU信息(动态加载,需分析AJAX请求)
    sku_info = []
    sku_script = soup.find('script', string=re.compile('skuMap'))
    if sku_script:
        sku_data = re.search(r'skuMap\s*:\s*({.*?})', sku_script.string)
        if sku_data:
            sku_json = json.loads(sku_data.group(1))
            for sku_id, sku in sku_json.items():
                sku_info.append({
                    'properties': sku['name'],
                    'price': sku['price'],
                    'stock': sku['stock']
                })
    
    # 提取店铺信息
    shop_name = soup.select_one('.slogo-shopname').text.strip()
    
    return {
        'title': title,
        'price': float(price),
        'sku_info': sku_info,
        'shop_name': shop_name
    }

二、京东商品详情解析

1. 页面结构特点

  • API 接口清晰:大部分数据通过 JSON 接口返回
  • 价格保护:价格信息可能需要登录才能获取
  • 动态评论:评论数据通过分页 API 加载

2. 核心字段解析

import requests
import json

def parse_jd_item(item_id):
    # 获取商品基本信息
    base_url = f"https://item.jd.com/{item_id}.html"
    headers = {
        'User-Agent': 'Mozilla/5.0',
        'Referer': base_url
    }
    
    # 获取商品标题和价格(需分析页面结构)
    response = requests.get(base_url, headers=headers)
    soup = BeautifulSoup(response.text, 'html.parser')
    title = soup.select_one('.sku-name').text.strip()
    
    # 通过价格API获取价格
    price_url = f"https://p.3.cn/prices/mgets?skuIds=J_{item_id}"
    price_data = requests.get(price_url, headers=headers).json()
    price = float(price_data[0]['p'])
    
    # 获取SKU信息
    sku_url = f"https://item-soa.jd.com/getWareBusiness?skuId={item_id}"
    sku_data = requests.get(sku_url, headers=headers).json()
    sku_info = []
    
    if 'wareSku' in sku_data and 'skus' in sku_data['wareSku']:
        for sku in sku_data['wareSku']['skus']:
            sku_info.append({
                'sku_id': sku['skuId'],
                'properties': sku['name'],
                'price': float(sku['price']),
                'stock': sku['stockState']
            })
    
    return {
        'title': title,
        'price': price,
        'sku_info': sku_info
    }

三、拼多多商品详情解析

1. 页面结构特点

  • 移动端优先:PC 端页面简化,数据主要来自移动端 API
  • 加密请求:请求参数和响应数据可能经过加密
  • 反爬严格:频繁请求会触发滑块验证

2. 核心字段解析

import requests
import json
import time
import random

def parse_pinduoduo_item(item_id):
    # 拼多多移动端API(示例,实际需分析最新接口)
    url = "https://apiv3.pinduoduo.com/api/item/get"
    
    # 构建请求参数(包含加密信息)
    params = {
        'item_id': item_id,
        'pdduid': int(time.time() * 1000),  # 模拟用户ID
        '_': int(time.time() * 1000),       # 时间戳
        'random': random.random()           # 随机数
    }
    
    # 添加必要的请求头
    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit',
        'Referer': f'https://mobile.yangkeduo.com/goods.html?goods_id={item_id}',
        'Origin': 'https://mobile.yangkeduo.com',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json, text/plain, */*'
    }
    
    # 发送请求
    response = requests.get(url, params=params, headers=headers)
    data = response.json()
    
    # 解析数据
    item = data.get('item', {})
    return {
        'title': item.get('goods_name'),
        'price': item.get('min_group_price') / 100,  # 拼多多价格单位为分
        'original_price': item.get('market_price') / 100,
        'sales': item.get('sales_tip'),
        'images': item.get('gallery'),
        'description': item.get('goods_desc')
    }

四、1688 商品详情解析

1. 页面结构特点

  • 企业级数据:包含更多供应商信息和批发属性
  • 多规格商品:SKU 结构复杂,支持混批
  • API 权限:部分数据需要授权访问

2. 核心字段解析

import requests
from bs4 import BeautifulSoup
import json

def parse_1688_item(item_id):
    # 1688商品详情页
    url = f"https://detail.1688.com/offer/{item_id}.html"
    headers = {
        'User-Agent': 'Mozilla/5.0',
        'Referer': 'https://www.1688.com'
    }
    
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 提取商品标题
    title = soup.select_one('.d-title').text.strip()
    
    # 提取价格范围
    price_range = soup.select_one('.price-now').text.strip()
    
    # 提取供应商信息
    company_name = soup.select_one('.company-name').text.strip()
    location = soup.select_one('.location').text.strip()
    
    # 提取SKU信息(动态加载)
    sku_info = []
    sku_script = soup.find('script', string=re.compile('skuMap'))
    if sku_script:
        sku_data = re.search(r'skuMap\s*:\s*({.*?})', sku_script.string)
        if sku_data:
            sku_json = json.loads(sku_data.group(1))
            for sku_id, sku in sku_json.items():
                sku_info.append({
                    'properties': sku['name'],
                    'price': sku['price'],
                    'min_order': sku['minOrderQuantity'],
                    'available_quantity': sku['availableQuantity']
                })
    
    return {
        'title': title,
        'price_range': price_range,
        'company_name': company_name,
        'location': location,
        'sku_info': sku_info
    }

五、唯品会商品详情解析

1. 页面结构特点

  • 品牌特卖:强调品牌和折扣力度
  • 限时活动:价格和库存时效性强
  • 移动端为主:PC 端功能简化

2. 核心字段解析

import requests
import json
import re

def parse_vip_item(item_id):
    # 唯品会商品详情API(示例,实际需分析最新接口)
    url = f"https://m.vip.com/product-{item_id}.html"
    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit',
        'Referer': 'https://m.vip.com/'
    }
    
    # 获取页面内容
    response = requests.get(url, headers=headers)
    html = response.text
    
    # 提取商品信息(JSON数据嵌入在页面script中)
    item_data = None
    match = re.search(r'window.productInfo\s*=\s*({.*?});', html)
    if match:
        item_data = json.loads(match.group(1))
    
    if not item_data:
        return None
    
    # 解析核心数据
    product = item_data.get('product', {})
    return {
        'title': product.get('name'),
        'brand': product.get('brandName'),
        'original_price': product.get('marketPrice'),
        'current_price': product.get('salePrice'),
        'discount': product.get('discount'),
        'images': [img.get('url') for img in product.get('detailImages', [])],
        'color_options': [color.get('name') for color in product.get('colors', [])]
    }

六、通用解析策略与注意事项

  1. 动态内容处理
  • 使用 Selenium/Puppeteer 渲染 JavaScript 内容
  • 注册直接获取 API 数据
  • 反爬应对:
  • 随机 User-Agent 轮换
  • 设置合理请求间隔(建议≥1 秒)
  • 使用 IP 代理池(Luminati、Oxylabs)
  • 数据验证:
  • 使用正则表达式验证价格、ID 等字段
  • 检查数据完整性,处理空值情况


通过分析各平台的页面结构特点和数据加载方式,结合适当的解析工具和反爬策略,可高效获取商品详情数据。建议针对具体平台定期更新解析逻辑,以应对页面结构变化。

请登录后查看

键盘上的蚂蚁 最后编辑于2025-07-11 16:16:30

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}}
沙发 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
打赏
已打赏¥{{reward_price}}
76
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
{{item.label}} 加精
{{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服