Fetch API not getting full HTML page

不羁岁月 提交于 2019-12-22 01:28:23

问题


I'm using the Fetch API to get some (public) data from a webpage. Here is my code:

const proxyurl = "https://cors-anywhere.herokuapp.com/";
var bookUrl = "the+old+man+and+the+sea";
var url = 'https://miss.ent.sirsidynix.net/client/en_US/mlsathome/search/results?qu=' + 
bookUrl + '&te=ILS';

fetch(proxyurl + url).then(function(result){
    return result.text();
}).then(function(text){
    var parser = new DOMParser();
    var html = parser.parseFromString(text, 'text/html');
    var divs = html.getElementsByTagName('div');
    var x = html.getElementsByTagName('thead');
    console.log(divs);
    console.log(x);
});

The output in the console for divs is "HTMLCollection(80)" so I know the page has loaded, but the output for x is "HTMLCollection(0)" meaning that it found no thead elements. However, when I look at the source code for the page, I can see multiple thead tags. whenever I load the page, the tables do take a little longer to load. How do I get the Fetch API to get the entire page?

来源:https://stackoverflow.com/questions/50847274/fetch-api-not-getting-full-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!