Find all the contents between two tags in python
<p>This is the first paragraph with some details</p>
<p><a href = "user1">This contains name of the user1</a>
<p><font>This is the contents from user1</font></p>
<p><a href = "user2">This contains name of the user2</a>
<p><font>This is the contents from user2</font></p>
This is the structure of my html. My aim is to extract the users and their
contents. In this case it should print all the contents between two 'a'
tags
The code which i tried is :
for i in soup.findAll('a'):
while(i.nextSibling.name!='a'):
print i.nextSibling
I returns me an infinite loop. So if anyone has idea how i can solve this
issue please share it with me.
No comments:
Post a Comment