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)
相关推荐
ALM专业人士15 小时前
【ALM】Polarion Project Templating and Updating功能升级,多项目批量更新一键搞定!
运维·汽车
湖南精循科技15 小时前
线上研讨会 | Ansys Mechanical & nCode 车灯振动疲劳分析
汽车·仿真·ansys·有限元分析·cae·结构·工程师
BSD_HY1 天前
L3智能驾驶上车之后,薄膜开关在人机交互中扮演什么角色?技术深度解析
汽车·人机交互·制造·薄膜开关
DarrenHChen_EDA1 天前
【汽车芯片功能安全分析与故障注入实践 05】Architectural、RTL、Netlist 三个阶段的安全分析差异
安全·汽车·功能安全·rtl·architecture·汽车芯片·netlist
合兴软件@2 天前
合兴软件重磅推出高性能HSM固件 国密算法赋能汽车信息安全新防线
网络·算法·网络安全·汽车·信息与通信
南宫萧幕2 天前
Simulink 发动机闭环控制仿真实战:从底层搭建、Scope 调试到论文级 MAP 图输出
人工智能·matlab·汽车·控制
深蓝易网2 天前
工厂目视化实操手册,告别形式主义
运维·网络·数据库·人工智能·汽车
图扑可视化2 天前
50ms 级实时数字孪生|汽车先进制造车间工艺流程
汽车·制造·数字孪生·智慧工厂
树欲静而风不止863 天前
汽车研发项目合规管控一体化首选平台-全星研发项目管理 APQP 软件系统
汽车
市象4 天前
赵明能享受到千里科技的推背感吗?
人工智能·ai·汽车