简体   繁体   English

使用C#在控制台应用程序中加载网页内容

[英]Load web page contents in console application using c#

I want to load contents of below web page in console application using c#. 我想使用c#在控制台应用程序中加载以下网页的内容。 http://justicecourts.maricopa.gov/findacase/casehistory.aspx http://justicecourts.maricopa.gov/findacase/casehistory.aspx

Using below code I am getting empty on the screen but it works perfectly if I load google.com web page. 使用下面的代码,我在屏幕上变得空了,但是如果我加载google.com网页,它可以完美地工作。

By using WebClient and WebRequest I was getting error "Please enable javascript" and content was not loading so I used below code and javascipt error is not displaying now but web page content is not loading. 通过使用WebClient和WebRequest,我收到错误消息“ Please enable javascript”,并且内容未加载,因此我在下面的代码中使用了javascipt错误,但现在未显示错误,但网页内容未加载。 I am struggling with this issue quite from long time, have seen lot of post regarding this and couldn't get this work. 我长期以来一直在为这个问题而苦苦挣扎,已经看到很多有关此问题的帖子,而无法完成这项工作。

Could anyone please help? 谁能帮忙吗?

Thanks in Advance.. 提前致谢..

class Program
{
    private static bool completed = false;
    private static WebBrowser wb;
    [STAThread]
    static void Main(string[] args)
    {
        wb = new WebBrowser();
        wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
        wb.Navigate("http://justicecourts.maricopa.gov/findacase/casehistory.aspx");
        while (!completed)
        {
            Application.DoEvents();
            Thread.Sleep(100);
        }
        Console.Write("\n\nDone with it!\n\n");
        Console.ReadLine();


    }

    static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        Console.WriteLine(wb.Document.Body.InnerHtml);
        completed = true;
    }

}

If you literally just want to dump the contents of that URL out to the console, try this: 如果您只是想将该URL的内容转储到控制台,请尝试以下操作:

using(WebClient client = new WebClient()) {
   Console.WriteLine(client.DownloadString(url));
}

try adding more wait. 尝试添加更多等待。

static void Main(string[] args)
    {
        wb = new WebBrowser();
        wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
        wb.Navigate("http://justicecourts.maricopa.gov/findacase/casehistory.aspx");
        while (!completed)
        {
            Application.DoEvents();
            Thread.Sleep(100);
        }
       //wait even more
       for (int i = 0; i < 6; i++)
        {
            Application.DoEvents();
            Thread.Sleep(1000);
        }
        Console.Write("\n\nDone with it!\n\n");
        Console.ReadLine();


    }

otherwise you can use EO Browser it is paid. 否则,您可以使用EO浏览器付费。 but in your case trail will work cause it is not GUI application.as it shows trail message in GUI. 但是在您的情况下,跟踪将起作用,因为它不是GUI应用程序。因为它在GUI中显示跟踪消息。

in EO you can say.. 在EO中你可以说..

EOContorol.WebView.LoadUrlAndWait(URL);

Try using PhantomJs basicaly like running a webbrowser without a window. 基本上像在没有窗口的情况下运行Web浏览器一样,尝试使用PhantomJs (headless) (无头)

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

相关问题 使用c#获取网页资源的控制台应用程序(javascript可能会导致此问题) - A console application to get a web page resource, using c# (javascript may cause this) 网页上的C#应用​​程序参数 - C# Application Parameters from Web Page 在ASP.NET C#中将网页上的内容另存为.doc - Saving the contents on a web page as .doc in asp.net c# 如何使用chrome控制台窗口和控制台命令获取网页的加载时间? - How to get the load time of a web page using chrome console window and console commands? 提示用户使用C#在网站上输入信息(不是控制台应用程序) - Prompt for user input on website using C# (not console application) 如何在C#Web表单应用程序的内容页面中添加脚本 - How to add script in content page of c# web form application 使用Javascript获取整个网页的内容 - Get at entire web page contents using Javascript C# function execute javascript function in web page using webclient - C# function execute javascript function in web page using webclient 如何使用C#将Web cam集成到aspx页面中? - how to integrate web cam in aspx page using c#? 如何将来自C#程序中Web浏览器小程序中加载的网页的参数传递回C#应用程序? - How can I pass an argument from a web page that is loaded inside a web browser applet in a C# program, back to the C# application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM