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)
相关推荐
LONGZETECH10 小时前
新能源汽车动力电池检测仿真教学系统:C/S 分层架构与数字化实训落地全解析
大数据·c语言·开发语言·人工智能·架构·系统架构·汽车
Godspeed Zhao17 小时前
跨越天际:从智能汽车到 eVTOL 的适航与系统级开发37——增强现实平显(AR-HUD)与合成视觉系统(SVS)在低能见度进近中的应用
汽车·ar·evtol
Luminbox紫创测控18 小时前
GB/T 5137.3 2020标准:汽车安全玻璃耐辐照与耐模拟气候试验方法
人工智能·测试工具·汽车·安全性测试·uv·测试标准
wuhanzhanhui1 天前
充电桩+三电技术2026武汉国际新能源汽车三电及充电桩技术展览会抢先看
汽车
DS小龙哥2 天前
基于树莓派PICO2设计的汽车少儿安全预警系统
网络·安全·汽车
云布道师2 天前
【云故事探索】NO.26 |小鹏汽车:一朵云上的AI造车之旅
人工智能·汽车
星创易联3 天前
2026智能驾驶新基建:车载以太网、5G-A与V2X如何重构“车路云”?
5g·汽车·车载通信·无人矿卡·车载网关
磐时信息技术3 天前
GB 44495/44496正式施行:智能网联汽车信息安全与软件升级进入强制合规阶段
网络安全·信息安全·汽车·gb44495·gb44496
wuhanzhanhui5 天前
汽车照明新势力崛起,2026武汉国际汽车电子车灯照明技术展览会抢先看
汽车
cd_949217215 天前
汽车诊断仪进入“软件定义设备”时代:谁能跑赢下半场
汽车