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)
相关推荐
Luminbox紫创测控1 天前
汽车座舱全光谱模拟:DIN 75220/ISO 4892-2标准要求与光源选型方案
汽车
Godspeed Zhao1 天前
现代智能汽车系统——CAN网络2
网络·汽车
热点速递1 天前
理想汽车“寒冬”未退,业绩小幅回暖掩盖深层阵痛
人工智能·汽车·业界资讯
Godspeed Zhao1 天前
现代智能汽车系统——其他总线1
汽车
码农小白AI2 天前
IACheck AI报告文档审核为新能源汽车高压安全检测报告审核提供支撑
人工智能·安全·汽车
fareast_mzh2 天前
解析汽车车架号VIN码
汽车
Eward-an2 天前
AI视觉赋能汽车零部件质检:迁移科技Epic Eye系统落地案例(技术深度解析)
人工智能·科技·汽车
汽车仪器仪表相关领域2 天前
便携即战力,全域无短板:PL-1 袖珍记录仪核心重构与场景落地全解
功能测试·重构·汽车·压力测试·可用性测试·ab测试
WINDHILL_风丘科技2 天前
IPEmotion曲线平滑计算:精准去除测试数据中的突起噪声
汽车·数据·噪声
达宽科技2 天前
教程 机器人线束通电检测怎么做?(二)
服务器·功能测试·机器人·汽车