Modify HtmlDocument
-
Hey Is it possible to use HtmlDocument, withouth the WebBrowser control? As you see, when the document is loaded in your WebBrowser control, you can fetch some html elements such as links, images, etc. But I want to set my own html in the HtmlDocument, and fetch the elements I want, withouth first using the WebBrowser to navigate to an url. My Idea is something like this:
HtmlDocument doc = webBrowser1.Document; for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++) { string url = doc.GetElementsByTagName("a")\[i\].GetAttribute("href"); }
But withouth have to use the WebBrowser control, and just set the html like this
doc.html = "<a href='link'>link ...</a>"
Please help me :sigh: Thanks in Advance - opx -
Hey Is it possible to use HtmlDocument, withouth the WebBrowser control? As you see, when the document is loaded in your WebBrowser control, you can fetch some html elements such as links, images, etc. But I want to set my own html in the HtmlDocument, and fetch the elements I want, withouth first using the WebBrowser to navigate to an url. My Idea is something like this:
HtmlDocument doc = webBrowser1.Document; for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++) { string url = doc.GetElementsByTagName("a")\[i\].GetAttribute("href"); }
But withouth have to use the WebBrowser control, and just set the html like this
doc.html = "<a href='link'>link ...</a>"
Please help me :sigh: Thanks in Advance - opxYup, you just need to get a webpage first (simply as text):
m_Client = new WebClient();
string webPage = m_Client.DownloadString(@"http://www.codeproject.com");Then you can write this string to a HtmlDocument using the
Write
method:HtmlDocument doc = new HtmlDocument();
doc.Write(webPage);
...
for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++)
{
string url = doc.GetElementsByTagName("a")[i].GetAttribute("href");
}My current favourite word is: Nipple!
-SK Genius
-
Yup, you just need to get a webpage first (simply as text):
m_Client = new WebClient();
string webPage = m_Client.DownloadString(@"http://www.codeproject.com");Then you can write this string to a HtmlDocument using the
Write
method:HtmlDocument doc = new HtmlDocument();
doc.Write(webPage);
...
for (int i = 0; i < doc.GetElementsByTagName("a").Count; i++)
{
string url = doc.GetElementsByTagName("a")[i].GetAttribute("href");
}My current favourite word is: Nipple!
-SK Genius