-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_questions.py
29 lines (24 loc) · 1 KB
/
get_questions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#http://www.quizwise.com/
import json
import urllib2
from bs4 import BeautifulSoup as soup
def get_json(link):
questions = []
html = urllib2.urlopen(link)
text = soup(html, "html5lib")
for question_block in text.find_all("div", {"class":"questionBlock"}):
for div in question_block.find_all("div", {"class": "question"}):
question = div.p.text.strip()
options = []
for div in question_block.find_all("div", {"class":"answer"}):
for div_answer in div.find_all("div", {"class":"answerText"}):
options.append(div_answer.text.strip())
for div in question_block.find_all("div", attrs={"color":"rgb(0, 136, 0)"}):
print div.text
dict = {}
dict["question"] = question
dict["options"] = options
dict["answer"] = ""
questions.append(dict)
print json.dumps(questions, sort_keys=True, indent=4, separators=(',', ': '))
get_json("http://www.quizwise.com/general-knowledge-quiz/2017-09-21")