用python结合jieba和wordcloud实现词云效果

yipeiwu_com6年前Python基础

0x00 前言

突然想做一个漏洞词云,看看哪些漏洞比较高频,如果某些厂商有漏洞公开(比如ly),也好针对性挖掘。就选x云吧(镜像站 http://wy.hxsec.com/bugs.php )。用jieba和wordcloud两个强大的第三方库,就可以轻松打造出x云漏洞词云。

github地址: https://github.com/theLSA/wooyun_wordcloud

本站下载地址:wooyun_wordcloud

0x01 爬取标题

直接上代码:

#coding:utf-8
#Author:LSA
#Description:wordcloud for wooyun
#Date:20170904

import urllib
import urllib2
import re
import threading
import Queue

q0 = Queue.Queue()

threads = 20

threadList = []

def gettitle():
 while not q0.empty():

 i = q0.get()
 url = 'http://wy.hxsec.com/bugs.php?page=' + str(i)
 html = urllib.urlopen(url).read()
 reg = re.compile(r'<li style="width:60%;height:25px;background-color:#FFFFFF;float:left" ><a href=".*?" rel="external nofollow" >(.*?)</a>')
 titleList = re.findall(reg,html)
 fwy = open("wooyunBugTitle.txt","a")
 for title in titleList:
 fwy.write(title+'\n')
 fwy.flush()
 fwy.close()
 print 'Page ' + str(i) + ' over!'

def main():
 for page in range(1,2962):
 q0.put(page)
 for thread in range(threads):
 t = threading.Thread(target=gettitle)
 t.start()
 threadList.append(t)
 for th in threadList:
 th.join()

 print '***********************All pages over!**********************'

if __name__ == '__main__':
 main()

0x02 打造词云

还是直接上代码:

# coding: utf-8

import jieba
from wordcloud import WordCloud
import matplotlib.pyplot as plt

data = open("wooyunBugTitle.txt","r").read()
cutData = jieba.cut(data, cut_all=True)
word = " ".join(cutData)

cloud = WordCloud(
 #设置字体,不指定可能会出现中文乱码
 font_path="msyh.ttf",
 #font_path=path.join(e,'xxx.ttc'),
 #设置背景色
 background_color='white',
 #词云形状
 #mask=color_mask,
 #允许最大词汇
 max_words=2000,
 #最大号字体
 max_font_size=40
 )

wc = cloud.generate(word)
wc.to_file("wooyunwordcloud.jpg") 
plt.imshow(wc)
plt.axis("off")
plt.show()

0x03 效果演示:

0x04 结语

由词云图可以看出,SQL注入依旧风光无限,其次是命令执行,继而是信息泄漏,整体看还是比较直观的。

相关文章

PyTorch中Tensor的维度变换实现

对于 PyTorch 的基本数据对象 Tensor (张量),在处理问题时,需要经常改变数据的维度,以便于后期的计算和进一步处理,本文旨在列举一些维度变换的方法并举例,方便大家查看。 维...

django与小程序实现登录验证功能的示例代码

之前用小程序做项目,因为后台使用的java开发,一切顺利,但切换成django做RESTful API接口时,在登陆注册时一直出现问题,网上搜索,借助一个网友的回答,找到了一种可行的解决...

Django使用HttpResponse返回图片并显示的方法

做了一个关于Django的小案例,想要在网页中显示图片,直接在img标签的src属性写图片的路径是不能显示的,查询资料发现在Django中使用图片这类的资源相当繁琐需要进行一定D的配置,...

获取django框架orm query执行的sql语句实现方法分析

获取django框架orm query执行的sql语句实现方法分析

本文实例讲述了获取django框架orm query执行的sql语句实现方法。分享给大家供大家参考,具体如下: 利用Django orM 可以很方便的写出很多查询,但有时候,我们需要检查...

python Django批量导入数据

前言: 这期间有研究了Django网页制作过程中,如何将数据批量导入到数据库中. 这个过程真的是惨不忍睹,犯了很多的低级错误,这会在正文中说到的.再者导入数据用的是py脚本,脚本内容参考...