Skip to content

Instantly share code, notes, and snippets.

@JDougherty
Created April 4, 2012 00:34
Show Gist options
  • Save JDougherty/2296700 to your computer and use it in GitHub Desktop.
Save JDougherty/2296700 to your computer and use it in GitHub Desktop.
FreeCCNAWorkbook Scraper
# This is a quick and dirty script to grab the practice questions from
# the Free CCNA Workbook (http://www.freeccnaworkbook.com/) to place
# each question in its own file and be able to view one question at a time
from BeautifulSoup import BeautifulSoup
import urllib2
page = urllib2.urlopen("http://www.freeccnaworkbook.com/labs/free-ccna-workbook-ccna-practice-exam/")
soup = BeautifulSoup(page)
divs=soup.findAll('div',attrs={"class" : "quizzin-question"})
i=1
for d in divs:
f = open('./'+str(i)+'.html', 'w')
q=d.find('div',attrs={"class" : "question-content"})
a=d.findAll('label')
f.write(q)
f.write('</br>')
for l in a:
f.write(l.text.encode("utf8").strip('\n'))
f.write('</br>')
f.write('<a href="'+str(i+1)+'">Next</a>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment