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)
相关推荐
天天爱吃肉821819 小时前
行业笔记|高压连接器瞬态接触退化通用检测方法论
人工智能·笔记·python·功能测试·学习·汽车
ranjun10231 天前
厂家金融定制方案:多元化低门槛购车,适配汉中各类人群资金需求
金融·汽车
康谋自动驾驶2 天前
GMSL2相机ROS2采集链路:多相机时序偏差降低方案
数码相机·自动驾驶·汽车·仿真测试
回眸&啤酒鸭2 天前
【回眸】搞钱灵感——智能体 汽车软件单元测试与集成测试
单元测试·汽车·集成测试
CoreTK_EMC2 天前
汽车电子元器件技术体系:EMC 防护类器件的车规要求与工程应用
汽车·芯通康·汽车电子元器件·车载 esd 防护·车规级 emc·车规 tvs 二极管·共模滤波器
小白学大数据3 天前
Python 爬虫实战:抓取汽车之家二手车成交价格与里程数据
开发语言·爬虫·python·汽车
ws2019073 天前
从实验室到路测场:2026广州测试测量展见证汽车品质新高度
科技·汽车
提升汽车音响好物3 天前
2026广州新能源汽车蔚来ES8音响升级施工记录:多单元系统如何重新安排车内声场
汽车·音频
威联通安全存储3 天前
TS-h1677AXU-RP 在汽车冲压车间高速冲压线检测网中的部署
python·汽车
LONGZETECH3 天前
大众 ID.4 CROZZ 整车级虚拟拆解:新能源汽车高压实训的数字化解决方案
c语言·开发语言·架构·汽车·汽车仿真教学软件