本次目的
python批量采集某商品数据
知识点:
requests 发送请求
re 解析网页数据
json 类型数据提取
csv 表格数据保存
开发环境:
python 3.8
pycharm
requests
代码
导入模块
import json
import random
import time
import csv
import requests
import re
import pymysql
# 连接数据库
def save_sql(title, pic_url, detail_url, view_price, item_loc, view_sales, nick):
count = pymysql.connect(
host='xxx.xxx.xxx.xxx', # 数据库地址
port=3306, # 数据库端口
user='xxxx', # 数据库账号
password='xxxx', # 数据库密码
db='xxxx' # 数据库表名
)
# 创建数据库对象
db = count.cursor()
# 写入sql
sql = f"insert into goods(title, pic_url, detail_url, view_price, item_loc, view_sales, nick) values ('{
title}', '{
pic_url}', '{
detail_url}', {
view_price

本文通过Python的requests库,详细讲解如何批量采集特定商品的数据。内容涵盖开发环境设置和关键代码展示,适合初学者实践操作。
&spm=1001.2101.3001.5002&articleId=123824285&d=1&t=3&u=32ac6fe818d9405596cda70e775882b9)
3583

被折叠的 条评论
为什么被折叠?



