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