When parsing long complicated html documents with beautifulsoup, it's sometimes useful to get the exact position in the original string where I've matched an element. I can't simply search for the string, as there may be multiple matching elements and I would lose bs4's ability to parse the DOM. Given this minimal working example:
import bs4
html = "<div><b>Hello</b> <i>World</i></div>"
soup = bs4.BeautifulSoup(html,'lxml')
# Returns 22
print html.find("World")
# How to get this to return 22?
print soup.find("i", text="World")
How can I get the element extracted by bs4
to return 22?