使用python揭秘CSDN热门付费专栏惊人真相

1.csdn付费专栏词云

我们如何分析csdn热门付费专栏呢?

在这里插入图片描述

热门专栏是动态的,所以我们爬取的数据是一直变化的!

通过我的分析得出如下结论,热门付费的领域:

  • 目标检测与计算机视觉:利用深度学习和图像处理技术,实现自动识别和定位目标物体的领域。
  • 系统开发与嵌入式:涉及设计、开发和优化嵌入式系统,包括硬件和软件的集成。
  • 数据科学与机器学习:通过分析和解释大量数据,利用机器学习算法构建模型,从中获取洞察和预测。
  • 物联网与人工智能:将传感器、设备和网络连接起来,通过人工智能技术实现智能化的互联网应用。
  • MATLAB应用:使用MATLAB编程语言和工具进行科学计算、数据分析、图像处理和模型开发等应用。

2.浏览器抓包分析

  • 1.我们首先找到CSDN排行榜页面

https://blog.csdn.net/rank/list/total
浏览器打开F12,点击网络

在这里插入图片描述

  • 我们停靠放上改为上下结构,如我上图

在这里插入图片描述

  • 点击如下图

首先我们点击热门专栏,然后我们点击Fetch/XHR,查看所有的网络请求
通过分析我们可以知道
在这里插入图片描述

  • 分析结果如下

https://blog.csdn.net/phoenix/web/blog/pay-column-rank?page=0&pageSize=20

在这里插入图片描述
在这里插入图片描述

3.API接口测试

我测试了

  • https://blog.csdn.net/phoenix/web/blog/pay-column-rank?page=0&pageSize=20
  • https://blog.csdn.net/phoenix/web/blog/pay-column-rank?page=0&pageSize=100
  • https://blog.csdn.net/phoenix/web/blog/pay-column-rank?page=0&pageSize=200
    通过测试发现,最多只能给到100个热门付费专栏数据

在这里插入图片描述

4.需要使用的python库

  • requests: 用于发送HTTP请求和处理响应的库。它可以用于与Web服务进行交互,例如获取网页内容或发送API请求。

  • pandas: 提供了用于数据操作和分析的数据结构和函数。它是一个功能强大的库,用于处理和分析结构化数据,例如表格数据。

  • wordcloud: 用于生成词云图的库。词云图是一种可视化形式,通过展示文本中出现频率较高的单词,以图形化的方式呈现文本数据。

  • matplotlib:
    用于创建静态、动态和交互式的可视化图表的库。它提供了各种绘图选项,可以用于创建线图、散点图、条形图、饼图等各种类型的图表。

pip install requests
pip install pandas
pip install wordcloud
pip install matplotlib

5.爬虫与数据分析设计

  • 首先我们需要做个爬虫,爬取API获取出的网络排行榜
import requests
import json


API_RANK = "https://blog.csdn.net/phoenix/web/blog/pay-column-rank"

# Http代理头
HTTP_headers = {
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
}

params = {'page': '0',
            'pageSize': 100}
response = requests.get(API_RANK, params=params, headers=HTTP_headers)
print("http:", response.url)
print("Status Code:", response.status_code)
print("Response Text:", response.text)


  • 我尝试把我们抓取到的数据写到excel中,我们来进行分析
import requests
import json
import pandas as pd

API_RANK = "https://blog.csdn.net/phoenix/web/blog/pay-column-rank"

# Http代理头
HTTP_headers = {
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
}

params = {'page': '0',
            'pageSize': 100}
response = requests.get(API_RANK, params=params, headers=HTTP_headers)
data = response.json()
print("http:", response.url)
print("Status Code:", response.status_code)
print("Response Text:", response.text)

def save_data_to_excel(data):
    df = pd.DataFrame(data)
    df.to_excel('data.xlsx', index=False)
    print("数据已成功保存到 data.xlsx 文件")
save_data_to_excel(data['data']["payColumnRankListItemList"])

在这里插入图片描述

  • 我们要分析高频词汇

    • 1.不可以分析高频词汇的时候拆分(C++,C#,OD等字样)
    • 2.根据高频词汇的出现数量来排名
def extract_top_keywords(,titles, fixed_words=None, min_count=2):
        fixed_words = {"OD", "C#", "JAVA", "C++", "华为", "Python"}
        # 创建自定义词汇表
        custom_vocab = set(fixed_words) if fixed_words else set()

        # 分词和清洗标题
        words = []
        for title in titles:
            # 使用正则表达式提取单词和数字
            tokens = re.findall(r'\w+', title)
            # 将单词转换为小写
            tokens = [token.lower() for token in tokens]

            # 将固定词汇作为整体添加到词汇表中
            for word in fixed_words:
                if word.lower() in title.lower():
                    tokens.append(word.lower())

            words.extend(tokens)

        # 统计词频
        word_counts = Counter(words)

        # 根据词频排序
        sorted_words = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)

        # 获取高频关键字和词汇
        top_keywords = [word for word, count in sorted_words if count >= min_count]

        return top_keywords

    def writePng(pic, title_list):
        # 将标题列表转换为字符串
        text = ' '.join(title_list)

        # 设置中文字体路径
        font_path = 'C:\\Windows\\Fonts\\simsun.ttc'  # 替换为你的中文字体路径

        # 创建词云对象并设置参数
        wc = WordCloud(font_path=font_path, background_color='white', width=800, height=600)

        # 生成词云
        wc.generate(text)

        # 显示词云
        plt.imshow(wc, interpolation='bilinear')
        plt.axis('off')
        plt.show()

        # 保存词云文件
        wc.to_file(pic)

6. 完整代码

import requests
import json
import pandas as pd
import re
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as plt

API_RANK = "https://blog.csdn.net/phoenix/web/blog/pay-column-rank"

# Http代理头
HTTP_headers = {
    'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
}

# http get 封装
class HttpRequest:
    header = None

    def __init__(self):
        return

    def request(self, URL, PARAMS):
        response = requests.get(URL, params=PARAMS, headers=HTTP_headers)
        print("http:", response.url)
        print("Status Code:", response.status_code)
        print("Response Text:", response.text)
        try:
            data = response.json()
            return data
        except json.JSONDecodeError:
            print("Error: The response is not in JSON format.")
            return None


class CSDNDataFetcher:
    def __init__(self):
        return

    def setHttpRequest(self, request):
        self.csdnGeter = request
        return

    # 获取排行榜
    def getRank(self, size):
        params = {
            'page': '0',
            'pageSize': size}
        data = self.csdnGeter.request(API_RANK, params)
        return data

    # 保存到excel中
    def save_data_to_excel(self, data):
        df = pd.DataFrame(data)
        df.to_excel('data.xlsx', index=False)
        print("数据已成功保存到 data.xlsx 文件")

    def read_column_from_excel(self, file_path, sheet_name, column_name):
        df = pd.read_excel(file_path, sheet_name=sheet_name)
        column_data = df[column_name].tolist()
        return column_data

    def extract_top_keywords(self, titles, fixed_words=None, min_count=2):
        fixed_words = {"OD", "C#", "JAVA", "C++", "华为", "Python","Matlab","Qt"}
        # 创建自定义词汇表
        custom_vocab = set(fixed_words) if fixed_words else set()

        # 分词和清洗标题
        words = []
        for title in titles:
            # 使用正则表达式提取单词和数字
            tokens = re.findall(r'\w+', title)
            # 将单词转换为小写
            tokens = [token.lower() for token in tokens]

            # 将固定词汇作为整体添加到词汇表中
            for word in fixed_words:
                if word.lower() in title.lower():
                    tokens.append(word.lower())

            words.extend(tokens)

        # 统计词频
        word_counts = Counter(words)

        # 根据词频排序
        sorted_words = sorted(word_counts.items(), key=lambda x: x[1], reverse=True)

        # 获取高频关键字和词汇
        top_keywords = [word for word, count in sorted_words if count >= min_count]

        return top_keywords

    def writePng(self, pic, title_list):
        # 将标题列表转换为字符串
        text = ' '.join(title_list)

        # 设置中文字体路径
        font_path = 'C:\\Windows\\Fonts\\simsun.ttc'  # 替换为你的中文字体路径

        # 创建词云对象并设置参数
        wc = WordCloud(font_path=font_path, background_color='white', width=800, height=600)

        # 生成词云
        wc.generate(text)

        # 显示词云
        plt.imshow(wc, interpolation='bilinear')
        plt.axis('off')
        plt.show()

        # 保存词云文件
        wc.to_file(pic)


#创建
r = HttpRequest()
obj = CSDNDataFetcher()
obj.setHttpRequest(r)

data = obj.getRank(100)
obj.save_data_to_excel(data['data']["payColumnRankListItemList"])

text = obj.read_column_from_excel("data.xlsx", "Sheet1", "columnName")
tiles = obj.extract_top_keywords(text)
obj.writePng("test.jpg", tiles)

7.最终的成果

你们真的好卷!!!
为了资本卷!!!
为了技术卷!!!
年底分多少钱!!!
今年加多少班!!!
绩效怎么样!!!
沉淀沉淀吧,有些事我都不知道怎么说。

在这里插入图片描述)

  • 目标检测与计算机视觉:YOLOv8、YOLOv5、YOLOv8-seg是目标检测算法的不同版本,芒果改进YOLO进阶指南和YOLOv8改进实战专栏提供了关于目标检测算法的改进和实践经验。此外,深度学习、点云处理、计算机视觉等也是与目标检测相关的热门领域。

  • 系统开发与嵌入式:华为OD机试专栏、Android开发、Autosar、FPGA、单片机、ARM开发等专栏涉及了系统开发、嵌入式开发、底层编程等方面的内容,适合对系统开发和嵌入式技术感兴趣的人。

  • 数据科学与机器学习:包括Python、R语言、XGBoost、BP神经网络、时间序列分析(ARIMA和GARCH)等专栏,涵盖了数据科学、机器学习、深度学习等领域的内容,适合对数据分析和机器学习算法感兴趣的人。

  • 物联网与人工智能:智能家居与物联网项目实战、物联网AIOT、ESP8266/ESP32等专栏关注物联网应用和物联网设备的开发,同时涉及到与人工智能相关的技术。

  • MATLAB应用:MATLAB专栏提供了各类MATLAB代码和工具的使用,适合对MATLAB编程和应用感兴趣的人。

8.惊人真相在这里

😳😳😳😳😳😳
你们好卷,再见!

  • 25
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程小鱼酱

用心写好每一篇博客

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值