python_BeautifulSoup爬取汽车评论数据

爬取的网站:

完整代码在文章末尾

https://koubei.16888.com/57233/0-0-0-2

使用方法:

复制代码
from bs4 import BeautifulSoup

拿到html后使用find_all()拿到文本数据,下图可见,数据标签为:

复制代码
content_text = soup.find_all('span', class_='show_dp f_r')

因为优点,缺点,综述的classname一样,所以写了个小分类:

python 复制代码
   for index,x in enumerate(content_text):
        if index % 3 == 0:
            with open("car_post.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")
        elif index % 3 == 1:
            with open("car_nev.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")
        else:
            with open("car_text.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")

结果预览

消极:

积极:

综述:

完整代码

python 复制代码
from bs4 import BeautifulSoup
import requests
for j in range(1,300):
    url="https://koubei.16888.com/57233/0-0-0-{}".format(j)
    headers={
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35"
    }
    resp=requests.get(url,headers=headers)
    resp.encoding="utf-8"
    soup=BeautifulSoup(resp.text,"html.parser")
    content_text = soup.find_all('span', class_='show_dp f_r')

    for index,x in enumerate(content_text):
        if index % 3 == 0:
            with open("car_post.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")
        elif index % 3 == 1:
            with open("car_nev.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")
        else:
            with open("car_text.txt", "a", encoding='utf-8') as f:
                f.write(x.text+"\n")
    print(j)
相关推荐
梅尔文.古10 小时前
ADCU-Ethernet-以太网在AUTOSAR与Linux架构下对比
arm开发·单片机·汽车
天天爱吃肉821819 小时前
【新能源汽车集成热管理系统压力检测技术全解析——从传感器原理到VCU控制策略】
汽车
是梦终空11621 小时前
汽车电子中的Service31应用与协议详解
网络·汽车
智塑未来1 天前
浙江润鑫STW-18汽车轮重测量仪 稳定可靠守护车辆运行安全
安全·汽车
科技圈快讯1 天前
浙江润鑫轴线车超载汽车检测秤:高精度检测,守护道路与车辆安全
安全·汽车
statistican_ABin1 天前
Python数据分析-宝马全球汽车销售数据分析(可视化分析)
大数据·人工智能·数据分析·汽车·数据可视化
taxunjishu1 天前
Profinet转MODBUS TCP汽车零部件工业自动化柔性产线方案
网络·自动化·汽车
LONGZETECH1 天前
职业院校新能源汽车专业仿真教学软件建设指南
架构·汽车·汽车仿真教学软件·汽车教学软件·新能源汽车仿真教学软件
ws2019072 天前
湾区锚点,技术聚合:AUTO TECH China 2026广州汽车零部件展启幕在即
人工智能·科技·汽车
WINDHILL_风丘科技2 天前
IPEmotion热流矩阵图在空调系统测试中的应用
汽车·空调·热流矩阵图