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)
相关推荐
事界见闻19 小时前
汽车备件自动化立体仓库该如何规划?借鉴丰田 45000 个 SKU 项目实践
大数据·自动化·汽车
大梦想家a2 天前
新能源汽车共享充电桩收费管理系统的设计与实现(SpringBoot+MyBatis-Plus+Vue,前后台分离完整源码)
spring boot·汽车·mybatis
TMT星球2 天前
智驾行业告别“烧钱”时代
汽车
yan418290dgjkv2 天前
2026年汽车贴膜获客新思路:3步锁定精准客户
python·汽车
CRMEB系统商城2 天前
汽车养护连锁的数字化底座CRMEB 多门店系统实战方案
java·开发语言·小程序·开源·汽车
水质在线监测仪厂家_慕迪科技3 天前
讲述如何正确地处理汽车涂装废水!
其他·汽车
AgentMaster3 天前
车型平台数据口径不一、供应链追溯断链?4 款数据治理系统选型对比与汽车行业落地记录
大数据·人工智能·汽车·交通物流
Luminbox紫创测控3 天前
车载AR-HUD阳光倒灌与热效应:太阳光模拟器如何复现太阳辐射?
测试工具·汽车·ar·安全性测试·测试标准
YOLO数据集集合4 天前
标准汽车行驶工况数据集(21种典型工况)| 汽车工况 行驶循环 油耗测试 排放认证 车辆仿真 交通能耗 标准数据集8018期
人工智能·目标检测·汽车·标准汽车行驶工况·汽车工况数据集·21
TMT星球4 天前
地平线征程智驾芯片量产突破1500万!
汽车