Created
January 18, 2011 18:35
-
-
Save brettkelly/784905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import urllib | |
reg = '[\&|\?]q=(?P<terms>[^\?\&$]+)' | |
rx = re.compile(reg) | |
tests = [ | |
'http://www.evernote.com/about/kb/search?lang=en&q=test', | |
'http://www.evernote.com/about/kb/search?q=foo+bar&lang=en', | |
'http://www.evernote.com/about/kb/search?lang=en', | |
'I AM A FAKE URL', | |
'http://www.evernote.com' | |
] | |
results = {} | |
for t in tests: | |
mo = rx.search(t) | |
if(mo): | |
terms = urllib.unquote(mo.group('terms')) | |
if terms in results: | |
results[terms] += 1 | |
else: | |
results[terms] = 1 | |
print results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment