title: How do I set a BeautifulSoup attribute while preserving HTML entities?
body: <p>Setup:</p>
  
  <pre class="lang-py prettyprint-override"><code>from bs4 import BeautifulSoup
  
  soup = BeautifulSoup('&lt;img/&gt;', 'html.parser')
  </code></pre>
  
  <p>I need to do the following:</p>
  
  <pre class="lang-py prettyprint-override"><code>soup.img['src'] = 'url?x=1&amp;y=2'
  </code></pre>
  
  <p>Desired behavior:</p>
  
  <pre class="lang-py prettyprint-override"><code>print(soup)
  &lt;img src="url?x=1&amp;y=2"/&gt;
  </code></pre>
  
  <p>Actual behavior:</p>
  
  <pre class="lang-py prettyprint-override"><code>print(soup)
  &lt;img src="url?x=1&amp;amp;y=2"/&gt;
  </code></pre>
  
  <p>In general, how do I set a <code>Tag</code> attribute to the literal string I'm passing in?</p>