def open_in_browser(response, _openfunc=webbrowser.open):
 from scrapy.http import HtmlResponse, TextResponse
 body = response.body
 if isinstance(response, HtmlResponse):
  if ('<base' not in body):
   repl = ('<head><base href="%s">' % response.url)
   body = body.replace('<head>', to_bytes(repl))
  ext = '.html'
 elif isinstance(response, TextResponse):
  ext = '.txt'
 else:
  raise TypeError(('Unsupported response type: %s' % response.__class__.__name__))
 (fd, fname) = tempfile.mkstemp(ext)
 os.write(fd, body)
 os.close(fd)
 return _openfunc(('file://%s' % fname))

def open_in_browser ( response , _openfunc = webbrowser . open ) : from scrapy . http import HtmlResponse , TextResponse body = response . body if isinstance ( response , HtmlResponse ) : if ( '<base' not in body ) : repl = ( '<head><base href="%s">' % response . url ) body = body . replace ( '<head>' , to_bytes ( repl ) ) ext = '.html' elif isinstance ( response , TextResponse ) : ext = '.txt' else : raise TypeError ( ( 'Unsupported response type: %s' % response . __class__ . __name__ ) ) ( fd , fname ) = tempfile . mkstemp ( ext ) os . write ( fd , body ) os . close ( fd ) return _openfunc ( ( 'file://%s' % fname ) )
open the given response in a local web browser .