Beispiel #1
0
        }//end ProcessTable

        public void ProcessList(Uri url, String listType, int optionList)
        {

            //ignore bad cert code
            IgnoreBadCertificates();

            //code to allow program with work with different authentication schemes
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            String listTypeEnd = listType + "/";
            //WebRequest http = HttpWebRequest.Create(url);
            FileWebRequest http = (FileWebRequest)WebRequest.Create(url);
            //HttpWebResponse response = (HttpWebResponse)http.GetResponse();
            FileWebResponse response = (FileWebResponse)http.GetResponse();
            Stream istream = response.GetResponseStream();
            ParseHTML parse = new ParseHTML(istream);
            StringBuilder buffer = new StringBuilder();
            bool capture = false;
            Advance(parse, listType, optionList);
            int ch;
            while ((ch = parse.Read()) != -1)
            {
                if (ch == 0)
                {
                    HTMLTag tag = parse.Tag;
                    if (String.Compare(tag.Name, "li", true) == 0)
                    {
                        if (buffer.Length > 0)
                            ProcessItem(buffer.ToString());
                        buffer.Length = 0;
                        capture = true;
                    }
                    else if (String.Compare(tag.Name, "/li", true) == 0)
                    {
                        // Console.WriteLine(buffer.ToString());  //creates a double listing of each list item, might be left over debugging code
                        ProcessItem(buffer.ToString());
                        buffer.Length = 0;
                        capture = false;
                    }
                    else if (String.Compare(tag.Name, listTypeEnd, true) == 0)
                    {
                        break;
                    }
                }
                else
                {
                    if (capture)
                        buffer.Append((char)ch);
                }
            }
        }//end ProcessList
Beispiel #2
0
 /// <summary>
 /// Advance to the specified HTML tag.
 /// </summary>
 /// <param name="parse">The HTML parse object to use.
 /// </param>
 /// <param name="tag">The HTML tag.</param>
 /// <param name="count">How many tags like this to find.
 /// </param>
 /// <returns>True if found, false otherwise.</returns>
 private bool Advance(ParseHTML parse, String tag, int count)
 {
     int ch;
     while ((ch = parse.Read()) != -1)
     {
         if (ch == 0)
         {
             if (String.Compare(parse.Tag.Name, tag, true) == 0)
             {
                 count--;
                 if (count <= 0)
                     return true;
             }
         }
     }
     return false;
 }
Beispiel #3
0
        /// <summary>
        /// Called to extract a list from the specified URL.
        /// </summary>
        /// <param name=”url”>The URL to extract the list
        /// from.</param>
        /// <param name=”listType”>What type of list, specify
        /// its beginning tag (i.e. <UL>)</param>
        /// <param name=”optionList”>Which list to search,
        /// zero for first.</param>

        public void ProcessTable(Uri url, int tableNum)
        {

            //ignore bad cert code
            IgnoreBadCertificates();

            //code to allow program with work with different authentication schemes
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            List<String> list = new List<String>();
            //WebRequest http = HttpWebRequest.Create(url);
            FileWebRequest http = (FileWebRequest)WebRequest.Create(url);
            //HttpWebResponse response = (HttpWebResponse)http.GetResponse();
            FileWebResponse response = (FileWebResponse)http.GetResponse();
            Stream istream = response.GetResponseStream();
            ParseHTML parse = new ParseHTML(istream);
            StringBuilder buffer = new StringBuilder();
            bool capture = false;
            Advance(parse, "table", tableNum);
            int ch;
            while ((ch = parse.Read()) != -1)
            {
                if (ch == 0)
                {
                    HTMLTag tag = parse.Tag;
                    if (String.Compare(tag.Name, "tr", true) == 0)
                    {
                        list.Clear();
                        capture = false;
                        buffer.Length = 0;
                    }
                    else if (String.Compare(tag.Name, "/tr", true) == 0)
                    {
                        if (list.Count > 0)
                        {
                            ProcessTableRow(list);
                            list.Clear();
                        }
                    }
                    else if (String.Compare(tag.Name, "td", true) == 0)
                    {
                        if (buffer.Length > 0)
                            list.Add(buffer.ToString());
                        buffer.Length = 0;
                        capture = true;
                    }
                    else if (String.Compare(tag.Name, "/td", true) == 0)
                    {
                        list.Add(buffer.ToString());
                        buffer.Length = 0;
                        capture = false;
                    }
                    else if (String.Compare(tag.Name, "/table", true) == 0)
                    {
                        break;
                    }
                }
                else
                {
                    if (capture)
                        buffer.Append((char)ch);
                }
            }
        }//end ProcessTable