예제 #1
0
        public WebPageContent DownloadWebSitePage(string url)
        {
            using (WebClient client = new WebClient())
            {
                var content  = client.DownloadString(url);
                var document = new HtmlDocument();
                document.LoadHtml(content);

                var result = new WebPageContent(document);

                return(result);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: ferib/CCNAdumper
        static void Main(string[] args)
        {
            StreamWriter writer;

            client = new WebClient();
            string WebPageContent, BodyContent;
            int    BodyStart = 0, BodyEnd = 0;
            string sBody   = "<body";
            string eBody   = "</body";
            bool   isSbody = false;
            bool   isEbody = false;

            //writer = new StreamWriter("G:\\ALL_Dump.txt");
            for (int i = 0; i < ccnaURL.Length; i++)
            {
                WebPageContent = client.DownloadString(ccnaURL[i]);
                writer         = new StreamWriter("G:\\CCNA-Exam-Answers-2019---DUMP\\" + FindElementData(WebPageContent, "<title>", "</title>", false)[0] + ".txt");
                for (int j = 0; j < WebPageContent.Length - eBody.Length; j++)
                {
                    isSbody = true;
                    for (int x = 0; x < sBody.Length; x++)
                    {
                        if (WebPageContent[j + x] != sBody[x])
                        {
                            isSbody = false;
                            break;
                        }
                    }
                    isEbody = true;
                    for (int x = 0; x < eBody.Length - 1; x++)
                    {
                        if (WebPageContent[j + x] != eBody[x])
                        {
                            isEbody = false;
                            break;
                        }
                    }
                    if (isSbody)
                    {
                        BodyStart = j;
                    }
                    if (isEbody)
                    {
                        BodyEnd = j;
                    }
                }
                BodyContent = WebPageContent.Substring(BodyStart, BodyEnd - BodyStart);
                List <string> Output = FindElementData(BodyContent, "<strong>", "</strong>", false);
                foreach (string unknown in Output)
                {
                    if (unknown[unknown.Length - 1] == '*')
                    {
                        Answairs.Add(unknown);
                        writer.WriteLine("A: " + unknown);
                    }
                    else
                    {
                        Questions.Add(unknown);
                        writer.WriteLine("Q: " + unknown);
                    }
                }
                writer.Close();
            }

            Console.WriteLine("Done!");
            Console.ReadLine();
        }