1. 首页
  2. 编程语言
  3. Python
  4. 使用Python获取商品销量的方法

使用Python获取商品销量的方法

上传者: 2023-09-03 13:28:46上传 RAR文件 958B 热度 19次
import requests 
import re 

def get_sales_data(url): 
    headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} 
    response = requests.get(url, headers=headers) 
    html = response.text 
    pattern = re.compile(r'"soldQuantity":(\d+)') 
    result = pattern.search(html) 
    if result: 
        return result.group(1) 
    else: 
        return None 

if __name__ == '__main__': 
    url = 'https://detai
下载地址
用户评论