Example #1
0
        private void DetailWeb()
        {
            txtMessage.Text = "";
            string                url;
            List <int>            lstInt;
            List <DBContext.Land> lst = db.LandNewList(out lstInt);
            // get Land
            string fileName;

            foreach (DBContext.Land item in lst)
            {
                url      = item.Url;
                fileName = pathDetail + @"\" + item.Id.ToString() + ".htm";
                if (File.Exists(fileName))
                {
                    continue;
                }

                if (!WebLib.HttpPost(url, pathDetail, item.Id.ToString()))
                {
                    txtMessage.AppendText("Không lấy được dữ liệu từ " + url);
                    txtMessage.AppendText(Environment.NewLine);
                    db.LandIsDetail(item.Id, true);
                }
                else
                {
                    txtMessage.AppendText("Lấy xong dữ liệu từ " + url);
                    txtMessage.AppendText(Environment.NewLine);
                }
            }
            DetailDisk();
        }
Example #2
0
        private void GenWeb()
        {
            txtMessage.Text = "";
            string code = db.UrlDefinitionList(2)[0].Code, url;
            // get Land
            int pageStart = Convert.ToInt32(txtPageStart.Text);
            int pageGet   = txtTotalPages.Text == "0" ? pageAll : Convert.ToInt32(txtTotalPages.Text);

            for (int page = pageStart; page <= pageGet; page++)
            {
                url = code.Replace("o=1", "o=" + page);
                if (!WebLib.HttpPost(url, pathGen, page))
                {
                    txtMessage.AppendText("Không lấy được dữ liệu từ " + url);
                    txtMessage.AppendText(Environment.NewLine);
                }
                else
                {
                    txtMessage.AppendText("Lấy xong dữ liệu từ " + url);
                    txtMessage.AppendText(Environment.NewLine);
                }
            }
            GenDisk();
        }
Example #3
0
        private void GenDisk()
        {
            int pageStart = Convert.ToInt32(txtPageStart.Text);
            int pageGet   = txtTotalPages.Text == "0" ? pageAll : Convert.ToInt32(txtTotalPages.Text);

            string[] files = Directory.GetFiles(pathGen);
            string[] lstSource = new string[28];
            string   str6 = pathGen + @"\" + WebLib.GetDateName(DateTime.Now.Date) + "-";
            int      index, count = 0;

            for (int i = pageStart; i <= pageGet; i++)
            {
                string str5;
                string str7 = str6;
                try
                {
                    str7  = str7 + i + ".htm";
                    count = 0;
                    StreamReader reader = new StreamReader(str7);
                    int          length;
                    if ((str5 = reader.ReadToEnd()) != null)
                    {
                        if ((length = str5.IndexOf("<div class=\"chotot-list-row\"")) >= 0)
                        {
                            str5 = str5.Substring(length + 31, str5.Length - length - 31);
                            while ((index = str5.IndexOf("title=\"")) >= 0)
                            {
                                str5         = str5.Substring(index + 7, (str5.Length - index) - 7);
                                length       = str5.IndexOf("\"");
                                lstSource[0] = str5.Substring(0, length).Trim(); //title

                                length        = str5.IndexOf("href=\"");
                                str5          = str5.Substring(length + 6, str5.Length - length - 6);
                                length        = str5.IndexOf("\"");
                                lstSource[22] = str5.Substring(0, length); //url
                                str5          = str5.Substring(length, str5.Length - length);


                                length        = str5.IndexOf("<div class=\"ad-price\"");
                                str5          = str5.Substring(length + 21, (str5.Length - length) - 21);
                                index         = str5.IndexOf(">");
                                str5          = str5.Substring(index + 1, (str5.Length - index) - 1);
                                index         = str5.IndexOf("</div>");
                                lstSource[19] = str5.Substring(0, index).Replace("đ", "").Replace(".", "").Trim(); //price
                                index         = str5.IndexOf("<span class=\"municipality\">");
                                str5          = str5.Substring(index + 27, (str5.Length - index) - 27);
                                index         = str5.IndexOf("</span>");
                                lstSource[26] = str5.Substring(0, index).Replace("ở", "").Trim(); //district

                                //<span class="subtext">(
                                index = str5.IndexOf("class=\"listing_thumbs_date\"");
                                if (str5.Substring(0, index).IndexOf("(Môi giới)") != -1)
                                {
                                    lstSource[7] = "true"; //isAgent
                                }
                                else
                                {
                                    lstSource[7] = "false"; //isAgent
                                }
                                str5          = str5.Substring(index + 27, str5.Length - index - 27);
                                index         = str5.IndexOf(">") + 1;
                                str5          = str5.Substring(index, str5.Length - index);
                                index         = str5.IndexOf("</div>");
                                lstSource[25] = str5.Substring(0, index).Replace("\r\n", "").Replace("\t", "").Trim(); //Posted DateTime
                                lstSource[25] = ParseDate(lstSource[25]);

                                index = str5.IndexOf("<div class=\"clear_row\"></div>");
                                str5  = str5.Substring(index + 29, str5.Length - index - 29);

                                lstSource = ClearTag(lstSource);
                                db.LandInsert(lstSource);
                                count++;
                            }
                        }
                        else
                        {
                            txtMessage.Text = txtMessage.Text + "Records: " + count + "Lỗi file: " + str7 + "!\r\n";
                        }
                    }
                    txtMessage.Text = txtMessage.Text + "Records: " + count + ". Xử lý xong file " + str7 + "!\r\n";
                    reader.Close();
                }
                catch (Exception) { txtMessage.Text = txtMessage.Text + "Records: " + count + "Lỗi file: " + str7 + "!\r\n"; }
            }
            txtMessage.Text += "Finish!";
            if (chkDelFile.Checked)
            {
                Array.ForEach(Directory.GetFiles(pathGen), delegate(string tempFile) { File.Delete(tempFile); });
            }
        }