Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from BeautifulSoup import BeautifulSoup
- doc = '''<html><head><title>Page title</title></head>
- <body>
- <div>
- <a href="..." title="text to highlight">Some text to highlight</a>
- <a href="..." title="text to highlight">Some other text to highlight</a>
- </div>
- </body></html>'''
- def transformText(original):
- return original + '!'
- soup = BeautifulSoup(doc)
- for div in soup.findAll('div'):
- for link in div.findAll('a'):
- link['title'] = transformText(link['title'])
- print soup.prettify()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement