Advertisement
Guest User

05. HTML Parser

a guest
Jan 18th, 2021
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. title_regex = r'<title>([^<>]*)<\/title>'
  5.  
  6. info = input()
  7.  
  8. title = re.findall(title_regex, info)
  9. title = ''.join(title)
  10. print(f"Title: {title}")
  11.  
  12. body_regex = r'<body>.*<\/body>'
  13.  
  14. body = re.findall(body_regex, info)
  15.  
  16. body = ''.join(body)
  17.  
  18.  
  19. content_regex = r">([^><]*)<"
  20.  
  21. content = re.findall(content_regex, body)
  22.  
  23. content = ''.join(content)
  24. content = content.replace('\\n', '')
  25.  
  26. print(f'Content: {content}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement