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 小时前
3.7 kW 无线电能传输系统-EXP-汽车-无线充电
自动化·汽车
Godspeed Zhao9 小时前
现代智能汽车系统——总线技术1
网络·汽车·php
摩尔元数10 小时前
2026年汽车仪表工厂选MES,厂商推荐
低代码·汽车·制造·mes
汽车仪器仪表相关领域10 小时前
MTX-A 模拟废气温度(EGT)计 核心特性与车载实操指南
网络·人工智能·功能测试·单元测试·汽车·可用性测试
深圳博众测控11 小时前
博众测控 | ISO 16750-2:2023汽车电气测试新标准解读:关键变化与测试设备选型
人工智能·测试工具·汽车
Amy1870211182311 小时前
直流绝缘监测装置在汽车充电桩中的应用
汽车
2501_9414185516 小时前
基于Mask-RCNN_X101-32x4d_FPN_2x_COCO的汽车凹陷与刮痕检测系统_1
汽车
老衲松哥16 小时前
【车辆动力学】汽车主销转向器受力分析
汽车
WINDHILL_风丘科技20 小时前
面对汽车三高试验挑战,TFM远程管理平台能否成为破局关键?
人工智能·汽车·github
纽格立科技20 小时前
【国标深读·技术篇】新能源汽车淘汰模拟中短波?车载数字广播才是强制国标的唯一解
汽车