2
我是新來的python。我有一個簡單的程序來查找單詞在網站中的使用次數。找到網站中最常用的詞
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
url = 'http://en.wikipedia.org/wiki/Albert_Einstein'
ourUrl = opener.open(url).read()
soup = BeautifulSoup(ourUrl)
dem = soup.findAll('p') #find paragraphs
for i in dem: # loop for each para
words = re.findall(r'\w+', i.text)
cap_words = [word.upper() for word in words]
word_counts = Counter(cap_words)
print word_counts
這是這給了我一個字段,而不是網站的總字數。需要做什麼改變。另外,如果我想過濾出像a,a這樣的常見文章,我需要包含哪些代碼。
相關,但沒有問到的東西:我會用nltk來查找單詞。 –