#!/usr/local/bin/python import re def pdf_icon(matchObj): ''' Take an opening anchor tag, it's text and the closing tag as an argument (as a regex match object), and return the same tag with the PDF icon SPAN as the first child element of the anchor (before the text). ''' icon_string = '<span class="icons icon-pdf"><span>PDF</span></span>' if '.pdf' in matchObj.group(1): # only add the icon to pdf links new_a = '{0}{1}{2}{3}'.format( matchObj.group(1), # {0} = opening A tag icon_string, # {1} = new SPAN matchObj.group(2), # {2} = text matchObj.group(3)) # {3} = closing tag return new_a else: return matchObj.group(0) # return the the original anchor, text and closing tag if it's not a PDF link regex_anchor = r'(<a.+?>)(.+?)(<\/a>)' #f = open('./license-requirements.html', 'r').read() # open the file f = ''' <h2>State Requirements </h2> <p>Requirements vary by state and the level of license. The requirements listed below are common across most states: </p> <ul> <li>Completion of degree — and in some instances additional academic credit's beyond a master's degree </li> <li>Specific coursework</li> <li>Background check and fingerprints</li> <li>Field experience, such as student teaching, internships, or practicum</li> <li>Successful exam completion, including the <a href="http://www.mtle.nesinc.com/">Minnesota Teacher Licensure Examinations (MLTE)</a></li> </ul> <h3>Unique State Requirements</h3> <p>Each state has different licensing requirements that are governed by a specific group or agency such as the state department of education. To understand your state's requirements, start by <a href="/email-us" rel="popup">contacting an enrollment counselor</a>. </p> <p>Additionally, you will want to do your own research on your state's requirements — the following resources may be helpful:</p> <ul> <li><a href="/assets/pdf/edLicensure/Educator-Licensure-Terms-2013.pdf">Educator licensure terms.</a></li> <li><a href="/assets/pdf/edLicensure/Understanding-Stats-Regs-Rules-2013.pdf">Understanding statues, regulations, and rules.</a></li> <li><a href="/education-degrees/licensure/state-resources">State resources</a></li> </ul> <p>Because Capella University has students in all 50 states and numerous countries, we have designed our programs to meet <a href="/about/awards-recognition/">national standards or accreditations </a>recognized by many states and have also sought approvals specific to Minnesota, Georgia, and Arizona.</p> <p>For most Capella students, earning a degree from Capella is similar to the rules and requirements if they were to earn a degree at a university outside of their state, and then move back to their state to pursue their professional license. Capella's enrollment counselors can provide specific information about unique educational requirements in your state. </p> <p><a href="/email-us" rel="popup">Email an enrollment counselor</a> or call 1.866.933.5981 to learn more.</p> <h3>Reciprocity and Transferring of Licenses</h3> <p>Generally, all states will accept another state's approved program or a license from another state, but there may be some additional requirements. This process is sometimes known as reciprocity. Reciprocity doesn't mean you can simply exchange your license in one state for a license in another. Reciprocity means that states are willing to accept graduates of another state's approved program, but still expect them to meet the same requirements as educators prepared in state. </p> <p>Capella's enrollment counselors can provide specific information about unique education requirements in your state. Contact an enrollment counselor to learn more. As you relocate and seek new opportunities, Capella's licensure resources and support will be available throughout your program.</p> <h3>Alternative Licensure Routes</h3> <p>Many states offer a less traditional option for earning an initial teaching license. Some also offer this option for administrator licenses. Generally, you must meet the same requirements as someone completing a degree program that is designed for teacher or administrator preparation — you just meet the requirements in a different way. For example, a licensure candidate may begin teaching in the classroom while still completing required course work or training.</p> <p>These alternative pathways require much more than simply passing exams. You will also be required to complete specific course work and training. If you're thinking of obtaining a license through an alternative route, carefully research the requirements and approved coursework providers for your state.</p> <p>Capella University does not offer degree programs that will help you earn a license through one of these alternative pathways.</p> <p>Capella University cannot guarantee licensure, certification, or endorsement. State regulations vary regarding professional licensure and salary benefits. It is learners' responsibility to understand and comply with requirements for their state. </p> ''' altered_f = re.sub(regex_anchor, pdf_icon, f) # look at every anchor tag on the page #new_f = open('./license-requirements2.html', 'w') # open a new so we still have the old one #new_f.write(altered_f) # write to the new file #new_f.close() # close the file. All done! print(altered_f)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question