Advertisement
johny_ferreira

find_tag_content.py

Nov 21st, 2021
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def find_tag_content(html, tag_name):
  2.     result = []
  3.     html = " " + html + " "
  4.     index_init = 0
  5.     index_end = 0
  6.     while index_init > -1:
  7.         index_init = html.find('<'+tag_name, index_init+1)
  8.    
  9.         index_end = html.find('</'+tag_name, index_end+1)
  10.  
  11.         if index_init > -1 and index_end > -1:
  12.             result.append(html[index_init+len(tag_name)+2:index_end])
  13.  
  14.     return result
  15.  
  16. html = "<p>blabla <strong>bloblo ble</strong> blub blu <strong> parara</strong> terere</p>"
  17.  
  18. print(find_tag_content(html, "strong"))
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement