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)
相关推荐
永霖光电_UVLED2 小时前
生物技术公司 BiomX 进军国防市场,计划收购 DFSL
人工智能·架构·汽车
Luminbox紫创测控1 天前
太阳光模拟器在汽车智能玻璃的运用
测试工具·汽车
羽翼未丰的啊博1 天前
DBC_2_C上位机
qt·车载系统·汽车
财经三剑客1 天前
深蓝汽车3月全球销量31742辆 环比增长87.8%
汽车
源码之家1 天前
计算机毕业设计:Python新能源汽车数据分析与个性化推荐系统 Django框架 snowNLP 协同过滤推荐算法 requests爬虫 可视化(建议收藏)✅
大数据·python·机器学习·数据分析·django·汽车·课程设计
数智顾问1 天前
(102页PPT)汽车设备企业信息化系统解决方案(附下载方式)
汽车
乐维_lwops2 天前
案例解读 | 某上市汽车企业集团基础监控+网管平台建设实践
网络·汽车·it基础监控
正午游巳2 天前
第二十六节:枚举和数组
汽车·autosar·汽车电子·车载嵌入式
永霖光电_UVLED2 天前
新能源汽车动力电池回收新规正式施行
汽车
智能化咨询2 天前
(144页PPT)DG1431汽车企业数智化战略规划(附下载方式)
汽车