I have a requirement wherein I store html text as string in python and want to compare them.
str1 = '<br> Example1'
str2 = '<br/> Example1'
If I do a normal str1 == str2, it will be False. But in html they are equal.
At the same time
str1 = '<br> Example1'
str2 = '<p> Example1'
is not html equal. Same goes with str2 = '<b> Example </b>' where str1!=str2
Are there any way to do it in python. I know the test case has self.assertInEmail which does html comparison, but I dont want to use test functions in my production code.
''.join(str1.split()) == ''.join(str2.split()). Though this will quickly go wrong. If you want to fully compare HTML, you're probably better off using a library like BeautifulSoup.