How to get offset position of a text in html page in python
Question: I am doing a webscraping to extract some text using beautiful soup.

I am successfully extracting the required text from the webpage but my new
requirement is along with the text I need to extract the offset
number/position where the text actually started and ended in the document.

Is there any possibility for this using beautiful soup or any helpful packages
for this ?

Please provide your thoughts and suggestions...

Thanks


Answer: Try to use following code

    
    
    import re
    
    DATA = "This is test message"
    
    for match in re.finditer(r'(?s)((?:[^\n][\n]?)+)', DATA):
        print match.start(), match.end()
    

Output

0 20

