bilibili

作者: Shawceng | 来源:发表于2018-06-24 20:09 被阅读0次

    数据爬取

    • 使用python 中的requests对bilibili api网站进行请求,对10100000到254100000的av号进行每隔500的遍历,也就是对哔哩哔哩所有视频进行间隔为500的样本抽样。
    • 使用多线程对网站进行请求,能够大量节省时间。其中在每个请求间隔0.2秒以防被反爬虫

    爬取过程

    1. 使用python 中的requests对bilibili api网站进行请求,对10100000到254100000的av号进行每隔500的遍历
    2. 再根据此视频的av号,获取相应的标签
    3. 再存储进数据库进行保存

    数据分析

    基本库为numpy, pandas, matplotlib

    1. numpy为基本库,用来大量实用操作
    2. pandas将数据转化为二维数据框,方便统计,排序等操作
    3. matplotlib可以用来大量的绘图工作,包括折线图,饼状图,条形图等, 包含大量操作

    图形的生成

    视频年上传量趋势

    首先生产pandas的DataFrame数据框,在对数据框进行以【视频上传量, 播放量】 进行排序,

    avs = AvInfo.query.order_by('created')
    av_list = [{'title': av.title, 'author': av.author, 'comment_count': av.comment_count,
                'favorite_count': av.favorite_count, 'play_count': av.play_count,
                'created': av.created.year, 'coin_count': av.coin_count} for av in avs]
    av_frame = DataFrame(av_list)
    year_count = pd.value_counts(av_frame.created)[:10]
    year_count[2018] = year_count[2018] * 2
    year_count = year_count.sort_values()
    

    然后绘制条形图, 先设置刻度线, 标题,x轴名称, y轴名称,再绘制折线图后绘制条形图,再为每个点添加值

    # 设置刻度
    plt.ylim(0,18000)
    plt.title('视频上传量年趋势') 
    plt.xlabel('year') 
    plt.ylabel('上传量') 
    # 制作折线图以及条形图 
    plt.plot(year_count, marker='*')
    plt.bar(year_count.index, year_count.values, 0.25, color='lightblue')
    plt.grid() 
    # 为每个点添加值
    for x, y in year_count.items():
        plt.text(x,y+300,str(y), ha='center') 
    plt.show() 
    

    得到图像:


    视频上传量年趋势.png

    关于词云

    该词云利用每个标签在所有视频中出现的次数进行统计,然后根据词的数量来生成每个关键字大小不同的图片。通过图片我们可以轻易的看到哪些标签是用户热衷的。


    word.png

    相关文章

      网友评论

          本文标题:bilibili

          本文链接:https://www.haomeiwen.com/subject/riusyftx.html