怎么打开html编辑器,在编辑器中打开html,而不是浏览

LWxmP.pngheaders = {

'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",

'upgrade-insecure-requests': "1",

'user-agent': "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36",

'referer': "http://civilinquiry.jud.ct.gov/GetDocket.aspx",

'accept-encoding': "gzip, deflate, sdch",

'accept-language': "en-US,en;q=0.8",

'cache-control': "no-cache",

}

new_response = TextResponse('https://doc.scrapy.org/en/latest/topics/request-response.html#response-objects', headers=headers, body='

Oh yeah!')

open_in_browser(new_response)

但是现在我看到在记事本而不是浏览器(在我的windows系统上)中打开的文本使我认为这是一个文本字符串而不是html(即使它有一个外部html标记):

我怎样才能让它工作?在

编辑:

我把密码改成

^{pr2}$

现在得到:TypeError: Unsupported response type: Response

编辑2:

我意识到在我版本的scrapy(1.1)中,源代码是:def open_in_browser(response, _openfunc=webbrowser.open):

"""Open the given response in a local web browser, populating the

tag for external links to work

"""

from scrapy.http import HtmlResponse, TextResponse

# XXX: this implementation is a bit dirty and could be improved

body = response.body

if isinstance(response, HtmlResponse):

if b'

repl = '

' % response.url

body = body.replace(b'

', 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)

我改变了对HTMLresponse的响应,它开始工作了。谢谢你

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值