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)
相关推荐
车企求职辅导5 小时前
AI Agent 在汽车上的应用
人工智能·汽车
汽车仪器仪表相关领域5 小时前
亲历机动车排放检测升级:南华NHA-604/605测试仪的实战应用与经验沉淀
人工智能·功能测试·测试工具·安全·汽车·压力测试
Godspeed Zhao6 小时前
现代智能汽车中的无线技术2——蜂窝移动通信技术(1)
汽车
硅农深芯6 小时前
深入解析 AECQ100 标准中的 Cpk:保障汽车电子元器件质量的关键指标
人工智能·算法·汽车·芯片·cpk
王夏奇6 小时前
新能源汽车热管理系统(Thermal Management System, TMS)基本知识入门
汽车
杨福宇6 小时前
对“智能网联汽车 组合驾驶辅助系统安全要求“国标徵求意见稿的反馈 -要帮助车厂
安全·自动驾驶·汽车·系统安全
雨大王5126 小时前
汽车制造业如何通过工业操作系统实现数字化转型?
汽车
ws20190718 小时前
空间革命将至?AUTO TECH China 2026广州汽车内外饰展解锁产业升级新路径
科技·汽车
王夏奇1 天前
新能源汽车的热管理系统-AI总结
汽车
雨大王5121 天前
汽车制造工艺开发如何实现智能化与绿色化转型?
汽车·制造