數據清洗demo 1

from urllib import urlopenhtml

from BeautifulSoup import BeautifulSoup as BSapp

import reurl

def ngrams(input,n):htm

    input=input.replace("\n","")ip

    input=input.split(' ')input

    output=[]it

    for i in range(len(input)-n+1):import

        output.append(input[i:i+1])programming

    return outputim

 

html=urlopen("https://en.wikipedia.org/wiki/Python_(programming_language)%22)")

bsObj=BS(html)

content=bsObj.find("div",{"id":"mw-content-text"})

ngrams=ngrams(str(content),2)

print ngrams

print "2-ngrams count is:" + str(len(ngrams))

相關文章
相關標籤/搜索