• Stars
    star
    216
  • Rank 182,120 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

根据关键词抓取微博数据,再生成词云

微博爬虫与词云展示

环境

  • Python 3
  • requests
  • jieba
  • matplotlib
  • wordcloud
  • scipy

爬虫

由于移动端网页版并未对爬虫做太大的限制,因此可以直接爬取微博搜索部分数据。搜索 API 如下:

https://m.weibo.cn/api/container/getIndex?type=wb&queryVal={}&containerid=100103type=2%26q%3D{}&page={}

基于这个 API 可以获取到一定量的 JSON 数据 (原始数据见 sample.json),经过处理后,格式如下:

{
    "mid": "4199434918992223",
    "text": "【深度学习的终极形态】近期,院友袁进辉博士回到微软亚洲研究院做了题为《打造最强深度学习引擎》的报告,分享了深度学习框架方面的技术进展。他在报告中启发大家思考如何才能“鱼和熊掌兼得”,让软件发挥灵活性,硬件发挥高效率。我们整理了本次报告的重点,希望能对大家有所帮助!  ​...全文",
    "userid": "1286528122",
    "username": "微软亚洲研究院",
    "reposts_count": 21,
    "comments_count": 1,
    "attitudes_count": 9
}

详细的爬虫见 weibo_search.py。

词云

词云的实现可以使用 wordcloud,基本的步骤是:

  1. 分词与关键词提取:中文的文本需要分词和去除大量的停用词,例如(你,我,他,这是), 才能使得生成的词云图更加具有意义。这一步,使用 jieba 分词器的 TF-IDF 关键词提取,就可以直接完成。

  2. 传入 wordcloud 的是一个字符串以及一幅底层图像,将第一步得到的关键词用空格串联起来, 对于底层图像的选取,尽量选择白底无背景图像,这样生成的图像就会更加接近原图。

代码详见 weibo_cloud.py。

样例

关键词:iPhone

apple

关键词:微软

microsoft

关键词:谷歌

google

More Repositories

1

text-classification-cnn-rnn

CNN-RNN中文文本分类,基于TensorFlow
Python
4,130
star
2

SpringMVCDemo

This is a demo of my spring mvc project.
Java
475
star
3

tf-idf-keyword

Keyword extraction based on TF-IDF on specific corpus. 基于特定语料库的TF-IDF的中文关键词提取
Python
150
star
4

char_rnn_lm_zh

language model in Chinese,基于Pytorch官方文档实现
Python
68
star
5

geo_convert

WGS84 / BD09 / GCJ02 / MapBar 经纬度坐标互转。Geolocation Conversion.
Python
50
star
6

baidu_hot_words

百度新闻的热搜关键词抓取,并根据关键词抓取新闻
Jupyter Notebook
44
star
7

keras-examples

Keras样例解析
Python
38
star
8

Chinese-Lyric-Corpus

A Chinese lyric corpus which contains nearly 50,000 lyrics from 500 artists
34
star
9

text-classification

CNN for sentence classification using Pytorch and MXNET
Jupyter Notebook
31
star
10

lyric_crawler_163

抓取网易云音乐歌手歌词
Jupyter Notebook
15
star
11

fancywriter

Using deep neural nets to write books
Jupyter Notebook
13
star
12

tf-rnnlm

simplified version of tensorflow language model on PTB data
Python
8
star
13

keras-doc-zh

https://keras-zh.readthedocs.io/
Python
7
star
14

pytorch-poem-generator

A Chinese Poem Generator based on PyTorch Char-RNN
Jupyter Notebook
6
star
15

keras-deep-learning

Notebook for Book "Deep Learning with Python"
Jupyter Notebook
4
star
16

crawl_scripts

爬虫脚本整理
Python
4
star
17

SpringDemo-List

这是一个SpringMVC绑定List参数的例子
Java
3
star
18

cpp_primer_plus

code of c++ primer plus (for practice)
C++
2
star
19

seq2seq-chatbot

Seq2Seq based chatbot
Jupyter Notebook
1
star
20

llm_from_scratch_code

code for book llm_from_scratch
Jupyter Notebook
1
star
21

Incentive

I have no idea what this repo is for, but this word just came into my mind.
1
star
22

screen_capture

windows下全屏截图
Batchfile
1
star
23

gaussic.github.io

HTML
1
star