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)
相关推荐
chipsense7 小时前
新能源汽车OBC/DCDC电流检测技术演进:HSxV系列如何赋能车载充电系统高效功率转换
汽车·霍尔电流传感器·sic·obc·800v·dc/dc·功率密度
3DVisionary10 小时前
突破接触式量测极点:汽车模具高精度蓝光3D扫描技术深度十问
重构·汽车·制造·蓝光3d扫描·汽车模具质检·全尺寸重构·形位公差分析
wechat_Neal11 小时前
智能座舱软件迭代速度差距的技术根源与突破路径
汽车
谁似人间西林客12 小时前
汽车点焊工艺智能升级 如何赋能制造提质增效
人工智能·汽车·制造
LONGZETECH12 小时前
破解智能网联汽车教学痛点!龙泽科技AR仿真软件,重新定义实训新范式
科技·架构·汽车·ar·职业教育·汽车仿真教学软件·汽车故障诊断
Godspeed Zhao1 天前
现代智能汽车中的无线技术11.3——TCU之智能驾驶数据回传
汽车·智能汽车
永霖光电_UVLED1 天前
奇瑞加速欧洲布局,扩产计划开启新征程
人工智能·生成对抗网络·汽车·制造·激光
盟接之桥1 天前
盟接之桥®制造业EDI软件:连接全球供应链的“数字桥梁”,赋能中国制造走向世界
大数据·网络·人工智能·汽车·制造
LONGZETECH1 天前
混合动力汽车动力系统仿真教学软件技术解析——职教数字化解决方案
架构·汽车·汽车仿真教学软件·汽车教学软件·汽车故障诊断
谁似人间西林客1 天前
2026汽车智能制造MES系统:AI升级路径与落地效果分析
人工智能·汽车·制造