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)
相关推荐
CoreTK_EMC14 小时前
汽车电子元器件技术体系:EMC 防护类器件的车规要求与工程应用
汽车·芯通康·汽车电子元器件·车载 esd 防护·车规级 emc·车规 tvs 二极管·共模滤波器
小白学大数据1 天前
Python 爬虫实战:抓取汽车之家二手车成交价格与里程数据
开发语言·爬虫·python·汽车
ws2019071 天前
从实验室到路测场:2026广州测试测量展见证汽车品质新高度
科技·汽车
提升汽车音响好物1 天前
2026广州新能源汽车蔚来ES8音响升级施工记录:多单元系统如何重新安排车内声场
汽车·音频
威联通安全存储1 天前
TS-h1677AXU-RP 在汽车冲压车间高速冲压线检测网中的部署
python·汽车
LONGZETECH1 天前
大众 ID.4 CROZZ 整车级虚拟拆解:新能源汽车高压实训的数字化解决方案
c语言·开发语言·架构·汽车·汽车仿真教学软件
dandan734621 天前
膜结构汽车棚厂家哪个技术先进?
汽车·膜结构汽车棚厂家
搜移IT科技2 天前
汽车内饰革订单饱满,兴业科技2026年成长逻辑清晰
科技·汽车
很楠爱上2 天前
(附上相关学习资源)适合新手做的第一个agent项目*ovo*Dify Agent 全栈实战:从智能选车顾问到新能源汽车之家的端到端开发
人工智能·汽车·agent·项目·开发笔记
天天爱吃肉82182 天前
【重磅发布:拿下新超仁达代理权 】
大数据·人工智能·python·功能测试·汽车