Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Modify HtmlDocument

Modify HtmlDocument

Scheduled Pinned Locked Moved C#
htmlhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OptiPlex
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • O OptiPlex

      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

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      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

      Game Programming articles start -here[^]-

      O 1 Reply Last reply
      0
      • A Anthony Mushrow

        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

        Game Programming articles start -here[^]-

        O Offline
        O Offline
        OptiPlex
        wrote on last edited by
        #3

        Hey, thanks allot for your reply, it worked exactly as I wanted! But anyway, when I reopened c#, it gave me an error on "new Htmldocument();" but il figure that out. Thanks again!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups