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)
相关推荐
向上的车轮9 小时前
飞桨PaddlePaddle:在汽车零部件制造中的工业自动化应用详解
汽车·制造·paddlepaddle
狮驼岭的小钻风9 小时前
汽车V模型开发流程、ASPICE、汽车功能安全的基石是国际标准 ISO 26262
网络·安全·汽车
毕设源码-郭学长1 天前
【开题答辩全过程】以 个性化汽车推荐系统为例,包含答辩的问题和答案
汽车
Godspeed Zhao1 天前
现代智能汽车中的无线技术72——SatCom(0)
汽车
天天爱吃肉82181 天前
【跨界封神|周杰伦×王传福(陶晶莹主持):音乐创作与新能源NVH测试,底层逻辑竟完全同源!(新人必看入行指南)】
python·嵌入式硬件·算法·汽车
AAD555888992 天前
基于YOLO13-C3k2-IDWC的汽车损伤检测技术研究_1
汽车
雨大王5123 天前
怎么打造一个能自我进化的制造数字基座?
人工智能·汽车·制造
JicasdC123asd3 天前
使用Faster R-CNN模型训练汽车品牌与型号检测数据集 改进C4结构 优化汽车识别系统 多类别检测 VOC格式
r语言·cnn·汽车
Godspeed Zhao3 天前
现代智能汽车中的无线技术11.1——蜂窝移动通信技术(11)
汽车·信息与通信
雨大王5123 天前
如何选择适合自己企业的工业智能体解决方案?
人工智能·汽车·制造