Scrapy - How to load html string into open_in_browser function
<p>I am working on some code which returns an <code>HTML</code> string (<code>my_html</code>). I want to see how this looks in a browser using <a href="https://doc.scrapy.org/en/latest/topics/debug.html#open-in-browser" rel="nofollow">https://doc.scrapy.org/en/latest/topics/debug.html#open-in-browser</a>. To do this I've tried to create a response object with body set to '<code>my_html</code>'. I've tried a bunch of things including:</p>

<pre><code>new_response = TextResponse(body=my_html)
open_in_browser(new_response)
</code></pre>

<p>based on the response class (<a href="https://doc.scrapy.org/en/latest/topics/request-response.html#response-objects" rel="nofollow">https://doc.scrapy.org/en/latest/topics/request-response.html#response-objects</a>). I'm getting:</p>

<pre><code>new_response = TextResponse(body=my_html)
  File "c:\scrapy\http\response\text.py", line 27, in __init__
    super(TextResponse, self).__init__(*args, **kwargs)
TypeError: __init__() takes at least 2 arguments (2 given)
</code></pre>

<p>How can I get this working?</p>

<p>Your error seems to be with the <code>TextResponse</code> initialization, <a href="https://doc.scrapy.org/en/latest/topics/request-response.html#textresponse-objects" rel="nofollow">according to the docs,</a> you need to initialize it with a URL, <code>TextResponse("http://www.expample.com")</code> should do it.</p>

<p>It looks like you are looking at the <code>Response</code> object docs and trying to use <code>TextResponse</code> like you would <code>Response</code>, by the looks of your optional argument and link to the docs.</p>

python scrapy