Change & # 39 to a regular character

I am having trouble displaying the contents of my program:

#! /usr/bin/python import urllib import re url = "http://yahoo.com" pattern = '''<span class="medium item-label".*?>(.*)</span>''' website = urllib.urlopen(url) pageContent = website.read() result = re.findall(pattern, pageContent) for record in result: print record 

exit:

 Masked teen killed by dad First look in &#39;Hotel of Doom&#39; Ex-NFL QB&#39;s sad condition Reporter ignores warning Romney&#39;s low bar for debates 

So the question is what should I include in my code to convert & # 39 to characters

+6
source share
2 answers

In Python2:

 In [16]: text = 'Ex-NFL QB&#39;s sad condition' In [17]: import HTMLParser In [18]: parser = HTMLParser.HTMLParser() In [19]: parser.unescape(text) Out[19]: u"Ex-NFL QB sad condition" 

In Python3:

 import html.parser as htmlparser parser = htmlparser.HTMLParser() parser.unescape(text) 
+9
source

in javascript:

  text = text.replace(/&#39;/g,"'"); 
0
source

Source: https://habr.com/ru/post/926543/


All Articles