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)
相关推荐
OpenCSG3 小时前
新能源汽车行业经典案例 — 某新能源汽车 × OpenCSG
大数据·人工智能·汽车·客户案例·opencsg
雨大王5129 小时前
数字化正如何将汽车产业链编织成一张智能协同一张网?
汽车
Ankie Wan12 小时前
AUTOSAR: Automotive Open System Architecture(汽车开放系统架构)
系统架构·汽车·ecu·autostar
Godspeed Zhao13 小时前
现代智能汽车中的无线技术33——V2X(5)
网络·汽车
来可电子-CAN1 天前
告别“选择性采集”,精准定位新能源汽车售后故障——4路CANFD数据记录仪替代方案解析
汽车·can·汽车电子·工程机械·煤矿
Gofarlic_oms11 天前
跨国企业Cadence许可证全球统一管理方案
java·大数据·网络·人工智能·汽车
厦门小杨1 天前
汽车内饰的面料究竟如何依靠AI验布机实现检测创新
大数据·人工智能·深度学习·汽车·制造·ai视觉验布机·纺织
Godspeed Zhao1 天前
现代智能汽车中的无线技术30——V2X(2)
网络·汽车
wechat_Neal1 天前
车载以太网技术全景-应用与工具篇
汽车