I am using BeautifulSoup to look for user entered word on a specific page, and highlight all this word. For example, I want to highlight the all words 'Finance' which located on the page 'https://support.google.com/finance/?hl=en&ei=VC8QVaH0N-acwgP36IG4AQ'.
#!/usr/bin/python
# charset=utf-8
import urllib2
import re
from bs4 import BeautifulSoup
html = urllib2.urlopen('https://support.google.com/finance/?hl=en&ei=VC8QVaH0N-acwgP36IG4AQ').read()
soup = BeautifulSoup(html)
matches = soup.body(text='Finance')
for match in matches:
match.wrap(soup.new_tag('span', style="background-color:#FE00FE"))
print soup
I found this variant of regex for word highlighting. But result document contain broken javascript