简体   繁体   English

如何使用 c# 或 Z686155AF75A17A0F6E9DED08 在 asp.net 中打开外部网站并获取其 html 内容

[英]How to open external website and get its html content in asp.net using c# or JavaScript

How to open external website in new window and get its html content in asp.net using c# or JavaScript How to open external website in new window and get its html content in asp.net using c# or JavaScript

var win = window.open('http://www.google.com'/* '../test.html'*/, "Popup", "width=550,height=300");
        var hm = "not set";

       
        //var hm = win.document.getElementsByClassName("hmdiv")[0].textContent;
        var timer = setInterval(function () {
           
            try {
               hm = win.document.getElementById("divhm").value;
   
            } catch (e) {

            }
            if (win.closed) {
                clearInterval(timer);
                alert('closed: ' + hm);
            }
        }, 1000);

If your requirement is only to get content from another page (and not need to display it in a new window), then perhaps this NuGet package will do what you need: AngleSharp .如果您的要求只是从另一个页面获取内容(并且不需要在新窗口中显示它),那么也许这个 NuGet package 将满足您的需求: AngleSharp

Here is example code from the GitHub page:这是来自 GitHub 页面的示例代码:

var config = Configuration.Default.WithDefaultLoader();
var address = "https://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(address);
var cellSelector = "tr.vevent td:nth-child(3)";
var cells = document.QuerySelectorAll(cellSelector);
var titles = cells.Select(m => m.TextContent);

make ajax call to retrieve the html.进行 ajax 调用以检索 html。

$.ajax({ url: "Website url", success: function(result){ $.ajax({ url: "网站网址", 成功: 函数(结果){

  $("#dvWebsite").html(result);

  

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM