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)
相关推荐
汽车仪器仪表相关领域2 小时前
光轴精准校准,安全检测基石——JZD-1/2前照灯检测仪用校准灯项目实战分享
数据库·算法·安全·汽车·压力测试·可用性测试
雨大王5123 小时前
智能能耗优化:汽车制造企业如何落地EMS系统
汽车·制造
Godspeed Zhao4 小时前
现代智能汽车中的无线技术11——蜂窝移动通信技术(10)
汽车·信息与通信
汽车仪器仪表相关领域5 小时前
多气精准检测,全场景适配——NHA-506/406型汽车排放气体测试仪项目实战分享
大数据·功能测试·单元测试·汽车·可用性测试·安全性测试
雨大王5125 小时前
汽车制造柔性排产:实现高效响应与资源优化的关键路径
汽车·制造
趣味科技v6 小时前
全维服务重构汽车消费体验:比亚迪方程豹4S店探店实录
重构·汽车
雨大王5126 小时前
汽车智能设计如何借助工业智能体提升研发效率
汽车
驭白.18 小时前
不止于自动化:新能源汽车智造的数字基座如何搭建?
大数据·人工智能·自动化·汽车·数字化转型·制造业
雨大王51220 小时前
工业AI大模型优化汽车生产排产:技术原理与实践案例
人工智能·汽车
应用市场20 小时前
图片格式完全指南——从JPEG到AVIF的技术原理与选型
网络·人工智能·安全·汽车