예제 #1
0
파일: VRX.cs 프로젝트: energiay/ParseVRX
        public void Run(object url)
        {
            VRXParse parse = (VRXParse)url;

            parse.Download();
            parse.GetContentVip();
            parse.GetContent();
        }
예제 #2
0
파일: VRX.cs 프로젝트: energiay/ParseVRX
        public VRX(string web, string findfolders, int page, string _namefile, int _top)
        {
            //threadCount = 1;
            threadCount      = 20;
            top              = _top;
            namefile         = _namefile;
            pageParse        = web;
            findfoldersParse = findfolders;
            //Thread thWatch = new Thread();
            VRXParse vrx = new VRXParse(pageParse, findfolders, page, namefile);

            ThreadVRX();
        }
예제 #3
0
        string geoLocation = "";    // Координаты через - ","


        /*string water;
         * string gas;
         * string sewerage;
         * string heating;*/
        ////////////////////////////////////


        public VRXParsePage(string idRecord)
        {
            /* if (idRecord == "213354_36018")
             * {
             *   idRecord = idRecord;
             * }
             * if (idRecord == "344195_36006")
             * {
             *   idRecord = idRecord;
             * }*/
            idRecord = pageRecordParse + idRecord + ".htm";
            IdRecord = idRecord;


            //Console.WriteLine("Загрузка " + idRecord);
            HtmlDocument record = Download(idRecord);

            // Если html получить не удалось
            if (record == null)
            {
                int i = 0; // кол-во попыток для запроса html
                while (record == null || i < 10)
                {
                    record = Download(idRecord);
                    i++;
                }

                if (record == null)
                {
                    Thread t = Thread.CurrentThread;
                    t.Abort();
                    VRXParse.SaveError("(VRXParsePage) Не удалось открыть страницу " + idRecord);
                }
            }
            //Console.WriteLine("Загрцзка " + idRecord + " окончена");
            //Console.WriteLine("");

            GetObj(record);
            GetSeller(record);
            SaveRecord();
            count++;
            //VRX.ConsoleWriteLineClear("Прочитано: " + count + " объяв. на стр. " + VRXParse.countPageParse, VRX.left, VRX.top);
        }
예제 #4
0
파일: VRX.cs 프로젝트: energiay/ParseVRX
        public void ThreadVRX()
        {
            // Потготовка CSV файла для записи
            //File.WriteAllText("vrx_all.csv", VRXParse.Utf8ToWin1251("sep=;\n"), Encoding.GetEncoding("windows-1251"));
            string head = "Объект;Район;Место;Адрес;Площадь(Общ);Этаж;Этажей;Материал;Тип;Участок(соток);Цена;Контакты;Дата;Текст;Координаты;Заголовок;Optional;Rayon;image1;image2;image3;image4;image5;image6;image7;image8;image9;image10" + "\n";

            File.WriteAllText(namefile, Utf8ToWin1251(head), Encoding.GetEncoding("windows-1251"));
            File.WriteAllText("vrx_error.txt", Utf8ToWin1251("Ошибки:"), Encoding.GetEncoding("windows-1251"));

            for (int i = 0; i < threadCount; i++)
            {
                VRXParse.GetNextPage();
                thList.Add(new Thread(new ParameterizedThreadStart(Run)));
                thList[thList.Count - 1].Name = "Thread#" + i;
                thList[thList.Count - 1].Start(new VRXParse(findfoldersParse, namefile));
            }

            ConsoleWriteLine("Всего страниц: " + VRXParse.countPageAll + " по 100 объявлений");

            string sDot = "";

            while (VRXParse.countPageParse <= VRXParse.countPageAll)
            //while (VRXParse.countPageParse <= 20)
            {
                for (int i = 0; i < threadCount; i++)
                {
                    if (thList[i].ThreadState.ToString() == "Stopped")
                    {
                        VRXParse.GetNextPage();
                        thList[i]      = new Thread(new ParameterizedThreadStart(Run));
                        thList[i].Name = "Thread#" + i;
                        thList[i].Start(new VRXParse(findfoldersParse, namefile));
                    }

                    //Console.WriteLine(thList[i].ThreadState.ToString());

                    /*ConsoleWriteLineClear(thList[i].ThreadState.ToString(), left, top);
                     * Thread.Sleep(1000);*/
                    //ConsoleWriteLineClear("Ждите, идет чтение "+ VRXParse.countPageParse.ToString() + " стр.", left, top);
                    //ConsoleWriteLineClear("Прочитано: " + VRXParsePage.count + " объяв. на стр. " + VRXParse.countPageParse.ToString(), VRX.left, VRX.top);
                    for (int j = 0; j < i; j++)
                    {
                        sDot += ".";
                    }

                    if (VRXParse.countPageParse <= VRXParse.countPageAll)
                    {
                        ConsoleWriteLineClear("Идет чтение " + VRXParse.countPageParse.ToString() + " страницы" + sDot);
                        sDot = "";
                        Console.WriteLine("");
                        Console.WriteLine("Запросов в Yandex за геопозицией: " + VRXParsePage.countYandex);
                    }

                    Thread.Sleep(200);
                }
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Ждем завершения " + threadCount + " потоков:");

            int  ThreadEND = 1; //Подсчитываем колличество потоков
            bool raning    = true;

            while (raning)
            {
                raning = false;

                for (int i = 0; i < threadCount; i++)
                {
                    if (thList[i] != null)
                    {
                        if (thList[i].ThreadState.ToString() == "Stopped")
                        {
                            Console.WriteLine(ThreadEND + ". " + "Thread#" + i + " завершил свою работу.");
                            ThreadEND++;
                            thList[i] = null;
                        }
                    }
                    if (thList[i] != null)
                    {
                        raning = true;
                    }
                }
            }

            for (int i = 0; i < threadCount + 10; i++)
            {
                Console.SetCursorPosition(0, top + i);
                Console.WriteLine("                                                              ");
            }
        }
예제 #5
0
        void GetObj(HtmlDocument record)
        {
            //HtmlNode bodyNode = record.DocumentNode.SelectSingleNode("//ul[@class='product-list']");
            HtmlNodeCollection pageNodes = record.DocumentNode.SelectNodes("//table[@class='text tbldetail']/tr/td");

            if (pageNodes != null)
            {
                for (int j = 0; j < pageNodes.Count; j++)
                {
                    //Console.WriteLine(j + ") " + pageNodes[j].InnerText);

                    //string str777 = pageNodes[j].InnerHtml;
                    if ((pageNodes[j].InnerText).IndexOf("Фотогалерея") > -1)
                    {
                        GetImg(pageNodes[j + 1].InnerHtml);

                        //str777 = pageNodes[j].Attributes["img"].Value;

                        /*var img = pageNodes[j].DocumentNode.SelectNodes("//img[@src]");
                         * // you can also check if link is not null
                         * var href = link.Attributes["href"].Value;*/
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Объект:") > -1)
                    {
                        GetSubject(pageNodes[j + 1].InnerText);
                    }

                    // Расположение
                    if ((pageNodes[j].InnerText).IndexOf("Месторасположение:") > -1)
                    {
                        GetLocation(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Адрес:") > -1)
                    {
                        GetAddress(pageNodes[j + 1].InnerText);
                    }

                    // площадь
                    if ((pageNodes[j].InnerText).IndexOf("Площадь:") == 0)
                    {
                        if ((pageNodes[j + 1].InnerText).IndexOf("/") > -1)
                        {
                            GetArea(pageNodes[j + 1].InnerText);
                        }
                        else
                        {
                            //GetArea(pageNodes[j + 1].InnerText);
                        }
                    }


                    // Этажность
                    if ((pageNodes[j].InnerText).IndexOf("Этаж/этажей:") > -1)
                    {
                        GetFloor(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Материал:") > -1)
                    {
                        GetMaterial(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Тип:") > -1)
                    {
                        GetType(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Участок:") > -1)
                    {
                        GetSector(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Стоимость:") > -1)
                    {
                        GetPrise(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Изменено:") > -1)
                    {
                        GetEditDate(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Операция:") > -1)
                    {
                        GetOperation(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Комнат:") > -1)
                    {
                        GetFlats(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Балкон:") > -1)
                    {
                        GetBalcony(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Санузел:") > -1)
                    {
                        bathroom = pageNodes[j + 1].InnerText;
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Наличие телефона:") > -1)
                    {
                        phone = pageNodes[j + 1].InnerText;
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Подвал:") > -1)
                    {
                        basement = pageNodes[j + 1].InnerText;
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Электричество:") > -1)
                    {
                        electricit = pageNodes[j + 1].InnerText;
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Комментарий к заявке:") > -1)
                    {
                        GetComment(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("Фирма продавец:") > -1)
                    {
                        GetFirm(pageNodes[j + 1].InnerText);
                    }

                    if ((pageNodes[j].InnerText).IndexOf("На карте:") > -1)
                    {
                        GetGeolocation(pageNodes[j + 1].InnerHtml);
                    }
                }
            }
            else
            {
                VRXParse.SaveError(" (VRXParsePage) Не получена таблица из HTML: " + IdRecord);
            }

            //HtmlNode bodyNode = record.DocumentNode.SelectSingleNode("//ul[@class='product-list']");
            HtmlNodeCollection pageNodesPhoto = record.DocumentNode.SelectNodes("//table[@id='fotoview']/tr/td[@id='fotoview_list']");


            if (pageNodesPhoto != null)
            {
                for (int j = 0; j < pageNodesPhoto.Count; j++)
                {
                    var str = pageNodesPhoto[j].InnerHtml;

                    //string str777 = pageNodes[j].InnerHtml;
                    if ((pageNodesPhoto[j].InnerHtml).IndexOf("mfoto") > -1)
                    {
                        GetImg(pageNodesPhoto[j].InnerHtml);
                    }
                }
            }


            //int i = 0;
        }