js 将\u003C这一类东西转换为标签

我们在抓取一些网站的时候可能会抓到一些\u003C这样的数据,这些代码是UNICODE编码值。可用js 的 unescape() 函数来解码。如:
document.write(unescape("\u003c\u003e")); // 输出:<>

import execjs

with open('js.js', encoding='utf8') as f:
    js = f.read()

js = execjs.compile(js)

str = "str = '&quot;\u003Cp\u003E巴西近日发生一起骇人夺婴案,一名23岁孕妇遭剖腹取婴惨死,而\&quot;子宫大盗\&quot;竟是13岁的亲妹妹。\u003C\u002Fp\u003E\u003Cimg src&#x3D;\&quot;http:\u002F\u002Fp1.pstatp.com\u002Flarge\u002Fpgc-image\u002FRgNfa7YDBeZOnd\&quot; img_width&#x3D;\&quot;480\&quot; img_height&#x3D;\&quot;319\&quot; alt&#x3D;\&quot;巴西孕妇遭剖腹取婴惨死 儿子溺亡 凶手

ret = js.call('f', str)

with open('2.html', 'w', encoding='utf8') as f:
    f.write(ret)

print(ret)

js.js

var f = function (str) {
    return unescape(str)
}

猜你喜欢

转载自www.cnblogs.com/zhangjian0092/p/11774289.html