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)
相关推荐
深圳南柯电子18 小时前
纯电汽车EMC整改:预防性设计节省47%预算|深圳南柯电子
网络·人工智能·汽车·互联网·实验室·emc
SelectDB技术团队20 小时前
货拉拉用户画像基于 Apache Doris 的数据模型设计与实践
数据分析·汽车·apache·用户画像·货拉拉
永霖光电_UVLED1 天前
Lumileds推出新的汽车前灯封装
汽车
Black蜡笔小新1 天前
赋能智慧货运:视频汇聚平台EasyCVR打造货运汽车安全互联网视频监控与管理方案
网络·汽车·音视频
易晨 微盛·企微管家1 天前
汽车行业SCRM:企业微信+服务商模式破解汽车服务行业痛点的案例分析
大数据·人工智能·汽车·产品运营·企业微信
紧固件研究社1 天前
汽车紧固技术加速进化,推动汽车产业迈向高质量制造新阶段
汽车·制造·紧固件
AcrelGHP1 天前
某汽车公司4S店携手Acrel-5000建筑能耗管理系统,实现连锁门店能源精细化管理新突破
汽车·能源
Serverless 社区2 天前
吉利汽车携手阿里云函数计算,打造新一代 AI 座舱推理引擎
人工智能·阿里云·汽车
世冠科技2 天前
世冠科技受邀参加第三十二届中国汽车工程学会年会暨展览会
汽车
老贾专利烩3 天前
汽车交互式系统专利拆解:VR/AR 画面生成与挡风玻璃异步转换的流畅性测试
汽车·ar·vr·信息与通信·科技前沿·创新专利