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)
相关推荐
MOS管-冠华伟业10 小时前
微硕双N-MOS管WST3392在汽车智能氛围灯系统中的应用
汽车
Tongyongtest8810 小时前
QC/T 216-2019 汽车用地毯检测
汽车·检测报告
luoganttcc2 天前
小鹏汽车 vla 算法最新进展和模型结构细节
人工智能·算法·汽车
准测仪器2 天前
新能源汽车中维修开关有什么作用?
汽车·电动汽车·仪器仪表·msd·维修开关·准测仪器
LabVIEW开发2 天前
LabVIEW汽车发动机振动测试
汽车·labview
yintele2 天前
智能AI汽车电子行业,EMS应用相关问题
人工智能·汽车
康谋自动驾驶2 天前
告别数月等待:数字孪生场景生成从此进入“日级”时代
汽车·测试·数字孪生·仿真·建模·3dgs
搞一搞汽车电子3 天前
S32K3平台eMIOS 应用说明
开发语言·驱动开发·笔记·单片机·嵌入式硬件·汽车
MOS管-冠华伟业3 天前
WSD3075DN56高性能MOS管在汽车电动助力转向系统(EPS)中的应用
汽车
老猿讲编程3 天前
从航空FACE的一个落地方案漫谈汽车HPC软件架构的思维转变(1/3)FACE基础概念与落地案例
汽车·软件架构