如何将来自xmlhttprequest的响应视为DOM对象,并使用getElementsByTagName()
之类的方法来解析它?我不控制要解析的页面,而是在content.js的上下文中进行Chrome扩展。
我有这个:
//prior to this there is a typical xmlhttprequest, which works fine
var webpage = xmlhttp.responseText;
//this returns an error: webpage.getElementsByTagName is not a function
//I've tried xmlhttp.responseText as well as xmlhttp.response
var elements = webpage.getElementsByTagName('*');
我很高兴在这里How to create DOM object from html page received over XMLHttpRequest?遇到类似的问题