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)
相关推荐
King's King5 小时前
厢式汽车货物自动装卸装置
汽车
王夏奇12 小时前
python在汽车电子行业中应用2—具体包的介绍和使用
网络·python·汽车
雨大王5121 天前
汽车AI智能体矩阵:驱动行业智能化变革的新范式
人工智能·汽车
无忧智库1 天前
汽车零部件行业破局之道:工业4.0智能工厂解决方案全景解析(PPT)
汽车
雨大王5121 天前
汽车零部件制造中质量缺陷识别的智能化解决方案
汽车·制造
汽车仪器仪表相关领域1 天前
AI赋能智能检测,引领灯光检测新高度——NHD-6109智能全自动远近光检测仪项目实战分享
大数据·人工智能·功能测试·机器学习·汽车·可用性测试·安全性测试
紧固件研究社1 天前
汽车紧固件,检测标准到底严在哪里?
汽车·制造·紧固件
深圳元器猫1 天前
板对板连接器解决方案:覆盖消费电子、汽车、工业全领域
汽车
F133168929571 天前
WD5030K,耐高压输出电流10A,WD5030A输出电流12A
网络·单片机·嵌入式硬件·物联网·汽车
高工智能汽车2 天前
CES2026丨中科创达发布滴水OS 2.0 Pre 以AI原生重构智能汽车交互体验
重构·汽车·ai-native