Skip to content

Instantly share code, notes, and snippets.

@noveoko
Last active March 19, 2017 00:11
Show Gist options
  • Save noveoko/e630e9b1375753bcb9fe22ba62df9449 to your computer and use it in GitHub Desktop.
Save noveoko/e630e9b1375753bcb9fe22ba62df9449 to your computer and use it in GitHub Desktop.
Someone posted a puzzle on the internet
#I wrote a script to extract +1,000 answers to this question.
#The results I came up with regarding the frequency of answers is:
#Counter({'6': 761, '3': 400, '9': 341, '-3': 100, '7': 100})
from bs4 import BeautifulSoup
import re
import collections
pattern = '([\-]*\d+)'
def extract_data_from_report3(filename):
soup = BeautifulSoup(open(filename), "html.parser")
trs = soup.find_all("span", class_="message-holder")
return trs
comments = extract_data_from_report3('all_answers.html')
numz = []
for comment in comments:
comment = comment.contents
numz.append(comment)
onlyInt = re.findall(pattern, str(numz))
c = collections.Counter(onlyInt)
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment