Skip to content

Instantly share code, notes, and snippets.

@acrymble
Created July 5, 2011 19:51
Show Gist options
  • Select an option

  • Save acrymble/1065739 to your computer and use it in GitHub Desktop.

Select an option

Save acrymble/1065739 to your computer and use it in GitHub Desktop.
Python HTML to Frequency Pairs
# html-to-freq-3.py
import obo
# create sorted dictionary of word-frequency pairs
url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
text = obo.webPageToText(url)
fullwordlist = obo.stripNonAlphaNum(text)
wordlist = obo.removeStopwords(fullwordlist, obo.stopwords)
dictionary = obo.wordListToFreqDict(wordlist)
sorteddict = obo.sortFreqDict(dictionary)
# compile dictionary into string and wrap with HTML
outstring = ""
for s in sorteddict:
outstring += str(s)
outstring += "<br />"
obo.wrapStringInHTML("html-to-freq-3", url, outstring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment