Python @ DjangoSpin

PyPro #57 Extract contents of a Paragraph tag with id 'para'

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Extract contents of a Paragraph tag with a given id in Python

Extract contents of a Paragraph tag with a given id in Python

Extract contents of a Paragraph tag with id 'para': Write a Regular Expression in Python to extract the contents lying between a paragraph tag with an id 'para'.

Extract contents of a Paragraph tag with id 'para'

import re

sourceString = '''
<p id = 'para'>Contents of paragraph</p>
'''

matchObject = re.search('<p id\s*=\s*\'para\'>(.*?)</p>', sourceString)

print(matchObject.group(1)) 			# 'Contents of paragraph'

To learn more about Regular Expressions in Python, click here.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply