[removed] how to fetch the content of a web page

前端 未结 4 1977
傲寒
傲寒 2021-02-06 07:38

In JS is it possible to fetch the content of a web page assigning it to a variable? For example, why the following toy code does not work?

var req = new XMLHttp         


        
4条回答
  •  有刺的猬
    2021-02-06 08:15

    use a server-side proxy like a php-page that reads the desired page and then make ajax calls to that proxy through javascript :

    var req = new XMLHttpRequest();
    
    req.open('GET', 'proxy.php?url=http://www.google.com', false);
    req.send(null);
    
    if(req.status == 200) {
       alert(req.responseText);
    }
    

提交回复
热议问题