I want to use it to invoke some JS scripts on the webpage. I have this:
static void Stuff()
{
WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.iana.org/domains/example/");
HtmlDocument doc = browser.Document;
//doc.InvokeScript("someScript");
Console.WriteLine(doc.ToString());
}
static void Main(string[] args)
{
Console.WriteLine("hi");
var t = new Thread(Stuff);
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
Question 1: I get an "object reference not set" exception when I try to get doc.ToString()
. Why?
Question 2: How do I get some data from the HTML document into the main program? WebBrowser
requires a separate thread, which requires a static method which can't return any value. How do I return, say, doc
to the Main()
so I can do something with it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…