title: How to parse weird Python Request response?
body: <p>I am doing a piece of work for a client and I need to get some data from their website.  Hitting their endpoint with a random post code the correct JSON results in success but the response is not what I'd expect.  </p>
  
  <p>It actually looks like it's valid JSON but contains escaped HTML in the HTML key as well as new line and returns before and after.</p>
  
  <p>I can parse it as a dictionary using:</p>
  
  <pre><code>json_string = json.loads(r.text)
  </code></pre>
  
  <p>I can't access the HTML key within it though as Python says it's a string..</p>
  
  <p>In fact I have no idea what to do.. any ideas how I can parse this in Python please so I can put the HTML into beautiful soup?  </p>
  
  <pre><code> {'d': '{\r\n  "result": "200",\r\n  "HTML": "&lt;table style=\\"max-width:750px;\\"&gt;&lt;tr id=\'resultsHeader2\'&gt;&lt;th class=\'thMid\'&gt;Select&lt;/td&gt;&lt;th class=\'thMid\'&gt;Address&lt;/td&gt;&lt;th class=\'thMid\'&gt;Street&lt;/td&gt;&lt;th class=\'thMid\'&gt;Area&lt;/td&gt;&lt;th class=\'thMid\'&gt;Postcode&lt;/td&gt;&lt;/tr&gt;&lt;tr class=\'tResults\' id=\'uprnRow0\'&gt;&lt;td id=\'uprnButton0\'&gt;&lt;button type=\'button\' onclick=\\"changeText(\'uprnButton0\',\'Loading\');populAddr(\'105 BERKSHIRE DRIVE RAMLEAZE SWINDON SN1 5RP\');getobject(\'divAddress\').innerHTML = \'\';GetInfoAndRoundsFor(\'345634564356\',\'SWN\');\\" title=\'Get Calendar for this address\'&gt;Show&lt;/button&gt;&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;BERKSHIRE DRIVE&lt;/td&gt;&lt;td&gt;RAMLEAZE&lt;br/&gt;SWINDON&lt;/td&gt;&lt;td&gt;SN1 5RP&lt;/td&gt;&lt;tr class=\'tResults\' id=\'uprnRow1\'&gt;&lt;td id=\'uprnButton1\'&gt;&lt;button type=\'button\' onclick=\\"changeText(\'uprnButton1\',\'Loading\');populAddr(\'150 BERKSHIRE DRIVE RAMLEAZE SWINDON SN15 5RP\');getobject(\'divAddress\').innerHTML = \'\';GetInfoAndRoundsFor(\'3456346435634\',\'SWN\');\\" title=\'Get Calendar for this address\'&gt;Show&lt;/button&gt;&lt;/td&gt;&lt;td&gt;150&lt;/td&gt;&lt;td&gt;BERKSHIRE DRIVE&lt;/td&gt;&lt;td&gt;RAMLEAZE&lt;br/&gt;SWINDON&lt;/td&gt;&lt;td&gt;SN15 5RP&lt;/td&gt;&lt;tr&gt;&lt;td class=\'tableFoot\' colspan=\'5\'&gt;&lt;/tr&gt;&lt;/table&gt;",\r\n  "r1": "Swindon",\r\n  "r2": "",\r\n  "r3": ""\r\n}'}
  </code></pre>
  
  <p>I've not seen it before and it looks hideous... :-)</p>
  
  <p>Updated with value of r.text:</p>
  
  <pre><code>{"d":"{\r\n  \"result\": \"200\",\r\n  \"HTML\": \"\u003ctable style=\\\"max-width:750px;\\\"\u003e\u003ctr id=\u0027resultsHeader2\u0027\u003e\u003cth class=\u0027thMid\u0027\u003eSelect\u003c/td\u003e\u003cth class=\u0027thMid\u0027\u003eAddress\u003c/td\u003e\u003cth class=\u0027thMid\u0027\u003eStreet\u003c/td\u003e\u003cth class=\u0027thMid\u0027\u003eArea\u003c/td\u003e\u003cth class=\u0027thMid\u0027\u003ePostcode\u003c/td\u003e\u003c/tr\u003e\u003ctr class=\u0027tResults\u0027 id=\u0027uprnRow0\u0027\u003e\u003ctd id=\u0027uprnButton0\u0027\u003e\u003cbutton type=\u0027button\u0027 onclick=\\\"changeText(\u0027uprnButton0\u0027,\u0027Loading\u0027);populAddr(\u00275 BERKSHIRE DRIVE RAMLEAZE SWINDON SN5 5RP\u0027);getobject(\u0027divAddress\u0027).innerHTML = \u0027\u0027;GetInfoAndRoundsFor(\u00345643564536\u0027,\u0027SWN\u0027);\\\" title=\u0027Get Calendar for this address\u0027\u003eShow\u003c/button\u003e\u003c/td\u003e\u003ctd\u003e5\u003c/td\u003e\u003ctd\u003eBERKSHIRE DRIVE\u003c/td\u003e\u003ctd\u003eRAMLEAZE\u003cbr/\u003eSWINDON\u003c/td\u003e\u003ctd\u003eSN5 5RP\u003c/td\u003e\u003ctr class=\u0027tResults\u0027 id=\u0027uprnRow1\u0027\u003e\u003ctd id=\u0027uprnButton1\u0027\u003e\u003cbutton type=\u0027button\u0027 onclick=\\\"changeText(\u0027uprnButton1\u0027,\u0027Loading\u0027);populAddr(\u002715 BERKSHIRE DRIVE RAMLEAZE SWINDON SN5 5RP\u0027);getobject(\u0027divAddress\u0027).innerHTML = \u0027\u0027;GetInfoAndRoundsFor(\u3456345634575\u0027,\u0027SWN\u0027);\\\" title=\u0027Get Calendar for this address\u0027\u003eShow\u003c/button\u003e\u003c/td\u003e\u003ctd\u003e15\u003c/td\u003e\u003ctd\u003eBERKSHIRE DRIVE\u003c/td\u003e\u003ctd\u003eRAMLEAZE\u003cbr/\u003eSWINDON\u003c/td\u003e\u003ctd\u003eSN5 5RP\u003c/td\u003e\u003ctr\u003e\u003ctd class=\u0027tableFoot\u0027 colspan=\u00275\u0027\u003e\u003c/tr\u003e\u003c/table\u003e\",\r\n  \"r1\": \"Swindon\",\r\n  \"r2\": \"\",\r\n  \"r3\": \"\"\r\n}"}
  </code></pre>