Search code examples
pythonescapingbeautifulsouphtml-escape-characters

BeautifulSoup is HTML escaping strings which have escaped characters


I am reading a string from file:

a = '<script>closedSign: \'<img src="/static/images/drop-down.png" style="margin-top: -3px;"  />\'</script>'

Now, when I run

BeautifulSoup(a)

<script>closedSign: '&lt;img src="/static/images/drop-down.png" style="margin-top: -3px;"   /&gt;'</script>

Thus, <img is being HTML escaped into &lt;img

How can I avoid this?


Solution

  • Use BeautifulSoup 3.2.0 instead of 3.2.1 to fix this problem.