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)
相关推荐
OCR_wintone42115 小时前
中安未来 OCR—— 开启高效驾驶证识别新时代
人工智能·汽车·ocr
Neituijunsir17 小时前
2024.09.22 校招 实习 内推 面经
大数据·人工智能·算法·面试·自动驾驶·汽车·求职招聘
QQ19284999063 天前
基于单片机汽车尾灯控制系统
单片机·嵌入式硬件·汽车
CyberSecurity_zhang3 天前
汽车信息安全 -- 再谈车规MCU的安全启动
网络安全·信息安全·汽车·安全启动
阿利同学3 天前
车辆种类分类识别数据集,可以识别7种汽车类型,已经按照7:2:1比 例划分数据集,训练集1488张、验证集507张,测试集31张, 共计2026张。
汽车·数据集·获取qq1309399183·车辆分类数据集
电气_空空3 天前
自动驾驶汽车横向控制方法研究综述
人工智能·自动驾驶·汽车·毕业设计·毕设
麦麦大数据3 天前
scrapy爬取汽车、车评数据【上】
scrapy·汽车
weixin_424381004 天前
Watchdog Timers(WDT)
mcu·汽车
阿川20154 天前
汽车革命下半场AI先锋:广汽为新“智”汽车装配大模型“底盘”
人工智能·大模型·汽车
芊言芊语5 天前
汽车灯光系统详细介绍
汽车