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)
相关推荐
财经三剑客6 小时前
长安汽车3月销量超27万辆 海外及新能源环比大幅增长
大数据·人工智能·汽车
永霖光电_UVLED7 小时前
Polar Light 获得了欧盟Eurostars计划的110万欧元(€1.1m)资助
大数据·人工智能·物联网·汽车·娱乐
北京聚信万通科技有限公司1 天前
北京聚信万通科技有限公司获Odette CA官方授权,成为中国区“Odette ID及数字证书”官方注册审批管理机构
网络·科技·汽车·edi·电子数据交换·国产软件
LONGZETECH1 天前
一线汽车教师实测:迈腾380TSI电气故障仿真软件,破解教学与大赛双重痛点
网络·科技·汽车·汽车仿真教学软件·汽车教学软件·新能源汽车仿真教学软件
永霖光电_UVLED1 天前
CEA-Leti 和 CEA-List 已宣布与 Powerchip 半导体制造公司 (PSMC) 合作
人工智能·生成对抗网络·汽车·制造·激光
申耀的科技观察1 天前
【观察】昂瑞微5G射频前端通过车规认证,筑牢智能网联汽车通信安全“底座”
前端·5g·汽车
ws2019072 天前
华南枢纽的产业引力:2026广州汽车内外饰展为何成行业必选项?
科技·汽车
zmj3203242 天前
汽车电子内部网络架构图
网络·汽车
Dotrust东信创智2 天前
HIL测试赋能功能安全:VT系统工具链筑牢智能汽车安全底线
安全·汽车
picoasis2 天前
汽车质量体系_3
汽车