create account

用Python分析虚拟币聊天室韭菜心理 by zhengkai

View this thread on: hive.blogpeakd.comecency.com
· @zhengkai · (edited)
$6.44
用Python分析虚拟币聊天室韭菜心理
<html>
<p>前几天闲的没事,去sosobtc的聊天室看了看,我发现那些人一天到晚乐此不疲的发些没用的消息。不是说哪个涨了多少跌了多少,就是问某某还能不能进,某某该不该卖了,买什么赚了多少倍,骂李笑来大骗子种种。。基本上可以看出韭菜们的贪婪恐惧和无知,和各种股票群里的对话差不多。</p>
<p><br></p>
<p>我突发奇想,想分析下那些虚拟币交易的韭菜们到底一天到晚再聊些什么。于是写了个程序抓取聊天室的聊天记录,然后保存到mysql,然后用Python做了下词云分析。</p>
<p>下面是词云的效果:</p>
<p><img src="http://ww1.sinaimg.cn/large/694a5846gy1fip5lctjrcj211y0iogr4.jpg" width="1366" height="672"/></p>
<p><br></p>
<p><img src="http://ww1.sinaimg.cn/large/694a5846gy1fip5leznsnj210z0g5n2k.jpg" width="1331" height="581"/></p>
<p><br></p>
<p>应该是当天蚂蚁大涨,所以频率比较高,可以看出韭菜们对消息和市场的反应。。。</p>
<p>准备工作:</p>
<p>首先准备好几个准备抓取得聊天室的地址,我准备的几个地址如下:</p>
<p>http://io.sosobtc.com/?chnl=okcoin&amp;theme=light&amp;nested=true&amp;app=true</p>
<p>https://io.sosobtc.com/?chnl=yunbi&amp;theme=light&amp;nested=false&amp;app=true</p>
<p>https://io.sosobtc.com/?chnl=biter&amp;theme=light&amp;nested=true&amp;app=true</p>
<p>https://io.sosobtc.com/?chnl=jubi&amp;theme=light&amp;nested=true&amp;app=true</p>
<p>可以很清楚的看到chnl就是不同的交易所,sosobtc支持很多个交易所,感兴趣的可以自己改参数试试</p>
<p>由于sosobtc的聊天室是基于websocket的,所以只需要在接收信息的地方拦截消息然后发送到本地后端保存就行了</p>
<p>这里我们使用Fiddle代理http://io.sosobtc.com/public/javascripts/app.js 这个js文件</p>
<p>然后找到</p>
<p><code>client.on('data', function onReply(data) {</code></p>
<p><code>receive(data);</code></p>
<p><code>});</code></p>
<p><br></p>
<p>可以看到这里调用receive方法来处理数据,于是在receive里面动动手脚就行啦。</p>
<p><img src="http://ww1.sinaimg.cn/large/694a5846gy1fip5y6jmfbj20u30ekmza.jpg" width="1083" height="524"/></p>
<p>可以看到我这里每次就是到消息就发送一个POST到本地http://localhost/msg,这样抓取数据就写好了</p>
<p>localhost里面的代码就很简单了,保存post到mysql,最后是Python的词云分析。</p>
<p>这一步也很简单,才几行代码,哈哈哈。。。</p>
<p><br></p>
<p><img src="http://ww1.sinaimg.cn/large/694a5846gy1fip5y6ztxbj20uv0ar0tm.jpg" width="1111" height="387"/></p>
<p>这里需要注意如果你的文本是中文需要引入支持中文的字体,我这里引入的微软自带的字体</p>
<p>就酱吧,有兴趣的可以研究研究,PY可以干很多好玩的事。</p>
<p>PS:</p>
<p>这里是我搜集的2w多条数据,可以下载自己跑的试试</p>
<p>https://www.dropbox.com/s/gebl89uopm0103l/msg2.txt?dl=0</p>
<p><br></p>
<p><br></p>
</html>
👍  , , , , , , , , , , ,
properties (23)
authorzhengkai
permlinkpython
categorycn
json_metadata{"tags":["cn","python","code","cn-writing","fun"],"image":["http://ww1.sinaimg.cn/large/694a5846gy1fip5lctjrcj211y0iogr4.jpg","http://ww1.sinaimg.cn/large/694a5846gy1fip5leznsnj210z0g5n2k.jpg","http://ww1.sinaimg.cn/large/694a5846gy1fip5y6jmfbj20u30ekmza.jpg","http://ww1.sinaimg.cn/large/694a5846gy1fip5y6ztxbj20uv0ar0tm.jpg"],"links":["http://io.sosobtc.com/?chnl=okcoin&amp;theme=light&amp;nested=true&amp;app=true","https://io.sosobtc.com/?chnl=yunbi&amp;theme=light&amp;nested=false&amp;app=true","https://io.sosobtc.com/?chnl=biter&amp;theme=light&amp;nested=true&amp;app=true","https://io.sosobtc.com/?chnl=jubi&amp;theme=light&amp;nested=true&amp;app=true","http://io.sosobtc.com/public/javascripts/app.js","http://localhost/msg,这样抓取数据就写好了","https://www.dropbox.com/s/gebl89uopm0103l/msg2.txt?dl=0"],"app":"steemit/0.1","format":"html"}
created2017-08-19 09:24:12
last_update2017-08-20 08:20:27
depth0
children2
last_payout2017-08-26 09:24:12
cashout_time1969-12-31 23:59:59
total_payout_value5.195 HBD
curator_payout_value1.240 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,954
author_reputation-24,976,149,703
root_title用Python分析虚拟币聊天室韭菜心理
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,248,062
net_rshares1,791,273,339,314
author_curate_reward""
vote details (12)
@motomania ·
Hi. I am a volunteer bot for @resteembot that upvoted you.
Your post was chosen at random, as part of the advertisment campaign for @resteembot.
@resteembot is meant to help minnows get noticed by re-steeming their posts
-----
To use the bot, one must follow it for at least 3 hours, and then make a transaction where the memo is the url of the post.
If you want to learn more - [read the introduction post of @resteembot](https://steemit.com/resteembot/@resteembot/how-to-use-resteembot).
If you want help spread the word - [read the advertisment program post](https://steemit.com/resteembot/@resteembot/how-to-help-resteem-bot-spread-the-word).
-----
Steem ON!
properties (22)
authormotomania
permlinkre-zhengkai-python-20170819t092606814z
categorycn
json_metadata""
created2017-08-19 09:26:03
last_update2017-08-19 09:26:03
depth1
children0
last_payout2017-08-26 09:26:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length662
author_reputation-56,301,550,001
root_title用Python分析虚拟币聊天室韭菜心理
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,248,172
net_rshares0
@tumutanzi ·
这个好玩,有意思。数据会说话。
properties (22)
authortumutanzi
permlinkre-zhengkai-python-20170819t232839170z
categorycn
json_metadata{"tags":["cn"],"app":"steemit/0.1"}
created2017-08-19 23:28:39
last_update2017-08-19 23:28:39
depth1
children0
last_payout2017-08-26 23:28:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length15
author_reputation193,777,509,634,731
root_title用Python分析虚拟币聊天室韭菜心理
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id12,302,868
net_rshares0