【问题标题】:how to get source of a page如何获取页面的来源
【发布时间】:2016-05-25 08:49:54
【问题描述】:

如何使用 java、c# 或任何其他网络语言获取 google、wikipedia 或任何其他页面的来源。另外,我如何使用 ajax 从互联网加载谷歌或任何其他网站。我试过了:

function ajaxFunction(){
    var ajaxRequest; // The variable that makes Ajax possible!
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    // Create a function that will receive data
    // sent from the server and will update
    // div section in the same page.
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('23');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }
    // Now get the value from user and pass it to
    // server script.
    ajaxRequest.open("POST", "https://www.google.com/search", true);
    ajaxRequest.send(null);
}

【问题讨论】:

  • 你不能直接这样做。了解同源政策。
  • @SLaks 是对的,你必须阅读一些关于Same-Origin Policy的内容

标签: jquery html asp.net


【解决方案1】:

您可以使用 HttpRequest 和 HttpResponse ,如果您需要代码来获取给定 URL 的页面内容,请告诉我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-30
    • 2012-08-03
    • 2014-05-03
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多