Python中的HTML标签云

时间:2010-07-05 15:51:47

标签: python html tag-cloud

我正在寻找一个简单的库,可以给它一组项:值对,它可以生成标签云作为输出。

库最好是python

1 个答案:

答案 0 :(得分:6)

在css文件中定义font-sizes。使用

中的类
size-0{
   font-size: 11px;
}

size-1{
   font-size: 12px;
}

等。达到您需要的字体大小。

然后只需使用此代码段:

CSS_SIZES = range(1, 7) # 1,2...6 for use in your css-file size-1, size-2, etc.

TAGS = {
    'python' : 28059,
    'html' : 19160,
    'tag-cloud' : 40,
}

MAX = max(TAGS.values()) # Needed to calculate the steps for the font-size

STEP = MAX / len(CSS_SIZES)

for tag, count in TAGS.items():
    css = count / STEP        
    print '<a href="%s" class="size-%s">%s</a>' % (tag, css, tag),

这就是全部。不需要图书馆; - )