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 小时前
泵控式电液主动悬架系统分层控制研究_论文复现
算法·汽车
江瀚视野1 天前
问界正式加入逸安启,赛力斯布局超充赛道意欲何为?
汽车
谁似人间西林客1 天前
汽车智能制造提质增效,柔性生产是核心破局点
人工智能·汽车·制造
永霖光电_UVLED1 天前
让光学钟从实验室走向现实
大数据·汽车·制造
紧固视界1 天前
汽车紧固件有哪些?应用场景与技术要求全解析(2026上海紧固件展专题)
人工智能·汽车·上海紧固件展·上海紧固件专业展
Godspeed Zhao1 天前
现代智能汽车中的无线技术15.6——TCU之远程诊断与运行监控
科技·汽车·智能网联汽车
LONGZETECH1 天前
【技术解析】智能网联汽车自动驾驶VR仿真教学软件——职教数字化落地方案
人工智能·自动驾驶·汽车·vr·汽车仿真教学软件·汽车教学软件·新能源汽车仿真教学软件
安当加密03011 天前
汽车 ECU “一芯一证” 实现详解:头部车企四级密钥体系实践
汽车·kms·车联网·供应链安全·国密算法·汽车行业·ota安全
crossoverJie1 天前
从企业版 Istio 迁移到社区版:一场给高速行驶汽车换轮胎的实践
云原生·汽车·istio
戴西软件1 天前
戴西CAxWorks.VPG车辆工程仿真软件|假人+座椅双调整 汽车仿真效率直接拉满
java·开发语言·人工智能·python·算法·ui·汽车