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)
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM