rplus.github.io icon indicating copy to clipboard operation
rplus.github.io copied to clipboard

[POST] How to parse html response without loading any images

Open Rplus opened this issue 10 years ago • 0 comments

How to parse html response without loading any images by Michal Pierzchala 2015-08-12 https://www.xfive.co/blog/how-to-parse-html-response-without-loading-any-images/

找東西時找到這篇蠻有興趣的文章 他希望做到的就是 parse HTML source code 時不觸發額外的 request

keypoint: document.implementation.createHTMLDocument() https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation/createHTMLDocument

這在處理 template 或是 把 HTML ajax 進來後的處理, 有很大的幫助 因為可以不觸發一堆 request 就把要的東西爬出來

這創建出來的 HTMLDocument 仍然可以用一般的 querySelector, getElement... 之類的 node method 非常棒~


test page: https://jsbin.com/fixahi/1/edit?js,output

support: IE9+


tw: https://twitter.com/RplusTW/status/710184068550414337 fb: https://www.facebook.com/rplus.tw/posts/1077852872282495

Rplus avatar Mar 17 '16 09:03 Rplus