Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2010
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. from BeautifulSoup import BeautifulSoup
  2.  
  3. doc = '''<html><head><title>Page title</title></head>
  4.       <body>
  5.       <div>
  6.       <a href="..." title="text to highlight">Some text to highlight</a>
  7.       <a href="..." title="text to highlight">Some other text to highlight</a>
  8.       </div>
  9.       </body></html>'''
  10.  
  11. def transformText(original):
  12.     return original + '!'
  13.  
  14.  
  15.  
  16.  
  17. soup = BeautifulSoup(doc)
  18.  
  19. for div in soup.findAll('div'):
  20.     for link in div.findAll('a'):
  21.         link['title'] = transformText(link['title'])
  22.  
  23. print soup.prettify()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement