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)
相关推荐
安当加密3 天前
智能网联汽车如何守住“信任根”? CAS 构建汽车行业专用密钥管理体系
汽车
LVXIANGAN3 天前
汽车智能座舱中LVDS、CAN、以太网、RTP的区别
自动驾驶·汽车
LONGZETECH3 天前
技术解析|比亚迪秦 PLUS EV 故障诊断仿真软件,院校实训落地最优解
汽车·汽车仿真教学软件·汽车教学软件
雨大王5123 天前
整车制造计划排程排产系统的创新与实践
人工智能·汽车·制造
RunsenLIu3 天前
基于 Spring Boot 3 与 Vue 3 的汽车租赁系统
vue.js·spring boot·汽车
ws2019073 天前
聚焦测试测量新机遇,AUTO TECH China 2026广州汽车技术展锚定行业未来
人工智能·科技·汽车
汽车仪器仪表相关领域4 天前
动态诊断充电中枢:DCA-8000型动态诊断充电系统 4S店/维修连锁/新能源服务站/车队维保全场景实战全解
人工智能·车载系统·汽车·负载均衡·压力测试·可用性测试
lfPCB4 天前
汽车电子的“热管理师”:铝基板在新能源汽车中的应用
汽车
天天爱吃肉82184 天前
【功率分析仪在新能源汽车研发测试中的核心应用与工程师能力进阶(实战版)】
人工智能·嵌入式硬件·机器学习·汽车
Godspeed Zhao5 天前
现代智能汽车中的无线技术108——ETC(2)
汽车