HTMLParser C# Library Freeware

Diese C# Klasse parst HTML-Tags in einer verketteten Liste und bietet viele Möglichkeiten zum
Durchlaufen der Bäume. Mit dem HTMLParser ist es sehr einfach möglich, bestimmte Inhalte von Webseiten zu parsen.

Wir empfehlen diese Klasse besonders für mobile Endgeräte, da die Klasse im gegensatz zum mobilen .NET Framework auch Cookies unterstützt.
-
This C# Class parses HTML-Tags into a double linked list and offers possibilities to walk through nodes easily.
It is very useful to obtain information from websites.

We suggest to use this class especially for mobile devices as it supports Cookies as opposed to the .NET Compact Framework.

Autor: Fabian Stern

csParser.zip
HTMLParser C# Library – Source
26 KB
Download

Beispiel Snippet zum Parsen von google.de:

using System;
using System.Collections.Generic;
using System.Text;
using SmartCoding;

namespace SmartCoding
{
    class Program
    {
        static void Main(string[] args)
        {
            HTMLParser p = new HTMLParser();
            string search = "Smart-Coding";
            p.Go("http://www.google.de/search?hl=de&q=" + System.Web.HttpUtility.UrlEncode(search) + "&num=100");

            HTMLTag first = p.FirstTag;
            List l = new List();

            while (first != null)
            {
                first = first.SeekNextTag(new string[] { "h3\tclass=r", "a" });
                if (first == null) break;
                HTMLTag end = first.SeekNextTag("/a");
                if (end == null) break;

                cSearchEntry e = new cSearchEntry();

                e.Link = first.GetAttr("href").Content;

                string s = p.Text(first, end);
                e.Title = s;

                first = first.SeekNextTag(new string[] { "div" });
                end = first.SeekNextTag(new string[] { "cite" });

                s = p.Text(first, end);
                e.Desc = s;

                l.Add(e);

            }

            Console.WriteLine(l.Count + " Entries");
            Console.Read();

        }
    }

    class cSearchEntry
    {
        public string Title = "";
        public string Desc = "";
        public string Link = "";
    }

}