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)
相关推荐
一 乐9 小时前
汽车租赁|基于SprinBoot+vue的汽车租赁管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·汽车·论文·毕设·汽车租赁管理系统
wohoo_wangzi10 小时前
苏州晟雅泰电子:关于汽车领域会用到的5类存储芯片,容量参数、设计方案和主要应用场景
嵌入式硬件·汽车
wechat_Neal11 小时前
Google AAOS 2026发布深度解析与对中国车企出海的战略启示
人工智能·microsoft·华为·汽车
华普微HOPERF12 小时前
国产数字隔离器,如何助力充电基建夯实汽车充电桩的电气防护能力
汽车·新能源·数字隔离器·国产替代·充电桩
IAR Systems1 天前
软件定义汽车:构建更安全、更智能的汽车应用软件
安全·汽车·嵌入式·iar
康谋自动驾驶1 天前
GMSL + 硬件PTP方案,真能让ADAS路测告别“数十毫秒偏差”吗?
汽车·数据采集·硬件·传感器·adas·时间同步
wechat_Neal1 天前
车载导航市场与技术对标分析报告
人工智能·华为·汽车
不懒不懒2 天前
基于 YOLOv10 的汽车机油滤芯缺陷检测系统(训练 + 测试 + 可视化 + 避坑)
yolo·汽车
戴西软件2 天前
AICrash智能行人保护:CAxWorks.VPG 如何让汽车安全仿真快人一步
人工智能·深度学习·汽车
wechat_Neal2 天前
华为花瓣地图海外版市场与技术对标分析报告
华为·汽车