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)
相关推荐
码视野14 小时前
完全开源-支持二开-可做毕业论文-汽车养护行业的门店预约与管理平台 — 从需求到原型的全栈实践
汽车
美味虾片1 天前
闪充登顶世界之巅 比亚迪“珠峰站”上线 全面推进闪充网络布局
汽车
南宫萧幕1 天前
车辆控制基础:从 EKF 状态估计到非线性 MPC 轨迹跟踪的闭环实现
算法·matlab·汽车·控制·pid
安当加密1 天前
汽车专用密钥管理系统(Automotive KMS)技术架构设计指南
汽车
LONGZETECH2 天前
新能源汽车专业升级,仿真教学软件科学布局指南
人工智能·架构·汽车·汽车仿真教学软件·汽车故障诊断
蓉蓉的数码视界2 天前
则成电子26年一季报:AI+汽车电子双轮驱动成效显著,营收增长26.68%
大数据·人工智能·汽车
Oflycomm2 天前
Wi-Fi 7汽车领域应用全景解析:智能座舱的“超高速神经中枢”如何重塑未来出行?
人工智能·车载系统·汽车·高通·wifi7·wifi模组
南宫萧幕2 天前
基于 Luenberger 观测器的 PMSM 无速度传感器 id=0 矢量控制系统 Simulink 建模与实现(一)
算法·matlab·汽车·控制
KIHU快狐2 天前
快狐KIHU|110寸壁挂触控一体机G+G电容屏安卓系统汽车展厅查询展示
android·python·汽车
VBsemi-专注于MOSFET研发定制2 天前
高端汽车零部件尺寸3D检测设备功率MOSFET选型方案:精密高效运动与成像电源驱动系统适配指南
3d·汽车