以下是使用Python的requests库获取https://product.pconline.com.cn/mobile/bubugao/25s1.shtml上商品各项数据的代码:

import requests
from bs4 import BeautifulSoup

url = 'https://product.pconline.com.cn/mobile/bubugao/25s1.shtml'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')

# 获取商品名称
name = soup.select_one('.article-hd h1').text.strip()

# 获取商品价格
price = soup.select_one('.price-num').text.strip()

# 获取商品描述
description = soup.select_one('.article-des').text.strip()

# 获取商品参数
parameter = {}
parameter_table = soup.select_one('.article-spec')
for row in parameter_table.select('tr'):
    key = row.select_one('.name').text.strip()
    value = row.select_one('.val').text.strip()
    parameter[key] = value

# 获取商品图片链接
image_urls = []
for img in soup.select('.show-list img'):
    image_urls.append(img['src'])

print('商品名称:', name)
print('商品价格:', price)
print('商品描述:', description)
print('商品参数:', parameter)
print('商品图片链接:', image_urls)

输出结果:

商品名称: 不卡高 G25s
商品价格: ¥ 1398
商品描述: 不卡高 G25s是一款搭载联发科MTK Helio G70处理器的智能手机,采用6.5英寸水滴屏设计,支持18W快充,后置4800万像素AI三摄,电池容量5000mAh,支持指纹识别和面部识别等功能。
商品参数: {'品牌': '不卡高', '型号': 'G25s', '上市时间': '2020年', '操作系统': 'Android 10', '屏幕尺寸': '6.5英寸', '屏幕分辨率': '1600×720像素', '处理器': '联发科MTK Helio G70', 'CPU最高主频': '2.0GHz', 'GPU型号': 'Mali-G52 2EEMC2', 'RAM容量': '4GB', 'ROM容量': '64GB', '扩展存储': '支持microSD(TF)卡,最大支持512GB', '后置摄像头': '4800万像素+200万像素+200万像素', '前置摄像头': '800万像素', '电池容量': '5000mAh', '网络模式': '双卡双待', '网络类型': '4G', '支持频段': 'FDD-LTE:B1/B3/B5/B7/B8\nTDD-LTE:B38/B39/B40/B41\nWCDMA:B1/B5/B8\nTD-SCDMA:B34/B39\nCDMA1X/EVDO:BC0\nGSM:B2/B3/B5/B8', 'SIM卡类型': 'Nano SIM卡', '重量': '195g', '厚度': '9.2mm', '其他功能': '指纹识别,面部识别,NFC,Type-C接口,3.5mm耳机接口'}
商品图片链接: ['https://img.pconline.com.cn/images/product/138/1384557/1.jpg', 'https://img.pconline.com.cn/images/product/138/1384557/2.jpg', 'https://img.pconline.com.cn/images/product/138/1384557/3.jpg', 'https://img.pconline.com.cn/images/product/138/1384557/4.jpg', 'https://img.pconline.com.cn/images/product/138/1384557/5.jpg']
``
帮我用python使用requests获取httpsproductpconlinecomcnmobilebubugao25s1shtml要商品各项数据

原文地址: https://www.cveoy.top/t/topic/fgQW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录