Ejemplo n.º 1
0
        public void DangNhap(ref ThongTinTaiKhoan tk)
        {
            tk.Cookie = new CookieContainer();
            var          response = RequestToWeb.GET(new Uri("https://www.ehenho.com/"), false, true, tk.Cookie);
            var          s        = RequestToWeb.ReadStream(response.GetResponseStream());
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(s);
            var value = document.DocumentNode.SelectSingleNode("//input[@type='hidden' and @name='csrfmiddlewaretoken']").Attributes["value"].Value;

            string data = $"login={tk.TaiKhoan}&password={tk.MatKhau}&remember=on&csrfmiddlewaretoken={value}&remember=on";

            response = RequestToWeb.POST(new Uri("https://www.ehenho.com/accounts/login/"), tk.Cookie, data, true,
                                         config_more: (request) =>
            {
                request.Accept  = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
                request.Referer = "https://www.ehenho.com/";
            });
            if ((response as HttpWebResponse)?.StatusCode == HttpStatusCode.Found)
            {
                tk.TrangThai      = "Đang nhập thành công";
                tk.ChoPhepGuiNhan = true;
            }
            else
            {
                tk.TrangThai = "Đăng nhập thất bại";
                tk.Cookie    = null;
            }
        }
        public void GuiTin(ThongTinTaiKhoan nguoigui, ThongTinTaiKhoan nguoinhan, string tieude, string noidung, Action <string> callback = null)
        {
            if (nguoigui.Cookie == null)
            {
                throw new Exception("Thiếu cookie");
            }

            var    htmlGet       = RequestToWeb.GET(new Uri("https://www.webtretho.com/forum/private.php?do=newpm"), false, true, nguoigui.Cookie).ReadStream();
            string securitytoken = htmlGet.Substring("SECURITYTOKEN = \"", "\";");

            string data = string.Join("&", new[]
            {
                $"recipients={nguoinhan.TaiKhoan}",
                "bccrecipients=",
                $"title={tieude}",
                $"message_backup={noidung}",
                $"message={noidung}",
                "wysiwyg=0",
                "iconid=0",
                "s=",
                $"securitytoken={securitytoken}",
                "do=insertpm",
                "pmid=",
                "forward=",
                "sbutton=Gửi tin nhắn",
                "savecopy=1 ",
                "parseurl=1",
            });

            var response = RequestToWeb.POST(new Uri("https://www.webtretho.com/forum/private.php?do=insertpm&pmid="), nguoigui.Cookie, data, false, true).ReadStream();
        }
Ejemplo n.º 3
0
        public void GuiTin(ThongTinTaiKhoan nguoigui, ThongTinTaiKhoan nguoinhan, string tieude, string noidung, Action <string> callback = null)
        {
            //Lấy thông tin tài khoản nhận thư
            if (string.IsNullOrEmpty(nguoinhan.Id))
            {
                var    thongTinNguoiNhanThu_Response  = RequestToWeb.GET(new Uri(nguoinhan.Url), false);
                string thongTinNguoiNhanThu_string    = RequestToWeb.ReadStream(thongTinNguoiNhanThu_Response);
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(thongTinNguoiNhanThu_string);
                var    thongTinNguoiNhanThu_message = document.DocumentNode.Descendants("li").Where(div => div.HasClass("message")).FirstOrDefault();
                string thongTinNguoiNhanThu_Url     = thongTinNguoiNhanThu_message.QuerySelector("a").GetAttributeValue("href", "");
                nguoinhan.Id = thongTinNguoiNhanThu_Url.Split('/')[7];
            }
            string guiThu_data     = string.Format("subject={0}&body={1}&submit=Gởi&ismessage=1", tieude, noidung);
            var    guiThu_Response = RequestToWeb.POST(new Uri(string.Format("http://www.timbangai.com/timbangai/account/messages/compose/{0}", nguoinhan.Id)), nguoigui.Cookie, guiThu_data, false);
            string guiThu_string   = RequestToWeb.ReadStream(guiThu_Response);

            if (guiThu_string == null)
            {
                nguoigui.ChoPhepGuiNhan = false;
                nguoigui.TrangThai      = "Chuyển tài khoản";
                nguoinhan.TrangThai     = "Gửi lỗi (Web không trả về dữ liệu để xử lý)";
                return;
            }

            if (guiThu_string == "")
            {
                nguoinhan.TrangThai = nguoigui.TaiKhoan;
            }
            else
            {
                nguoinhan.TrangThai = "Gửi lỗi";
            }
        }
Ejemplo n.º 4
0
        public void DangNhap(ref ThongTinTaiKhoan tk)
        {
            tk.Cookie = new CookieContainer();
            #region Lấy cookie ban đầu
            var cookieBanDauResponse = RequestToWeb.GET(new Uri("http://cdn.likeyou.vn/sites/all/themes/jam_likeyou/images/bgfacbookren.png"), true, false, tk.Cookie);
            //var cookieBanDauResponse = RequestToWeb.GET(new Uri("http://media.likeyou.vn/"), true, false, tk.Cookie);
            #endregion

            #region Đăng nhập
            string data             = string.Format("name={0}&pass={1}&remember_me=1&form_id=user_login", tk.TaiKhoan, tk.MatKhau);
            var    dangNhapResponse = RequestToWeb.POST(new Uri("http://likeyou.vn/vi/user?destination=user"), tk.Cookie, data, false, true);
            string res = RequestToWeb.ReadStream(dangNhapResponse);
            if (dangNhapResponse.ResponseUri != null &&
                dangNhapResponse.ResponseUri.Query != null &&
                dangNhapResponse.ResponseUri.Query.Contains("user="******"Đang nhập thành công";
                tk.ChoPhepGuiNhan = true;
            }
            else
            {
                tk.TrangThai = "Sai tài khoản hoặc mật khẩu";
            }
            #endregion
        }
Ejemplo n.º 5
0
        public static void Test()
        {
            ThongTinTaiKhoan tk = new ThongTinTaiKhoan();

            tk.Cookie = new CookieContainer();
            var cookieBanDauResponse = RequestToWeb.GET(new Uri("http://media.likeyou.vn/"), true, false, tk.Cookie);

            tk.TaiKhoan = "*****@*****.**";
            tk.MatKhau  = "*****@*****.**";

            string data             = string.Format("name={0}&pass={1}&remember_me=1&form_id=user_login", tk.TaiKhoan, tk.MatKhau);
            var    dangNhapResponse = RequestToWeb.POST(new Uri("http://likeyou.vn/vi/user?destination=user"), tk.Cookie, data, false, true);
            string res         = RequestToWeb.ReadStream(dangNhapResponse);
            var    loginHeader = RequestToWeb.ReadHeader(dangNhapResponse.Headers);

            if ((dangNhapResponse as HttpWebResponse).StatusCode == HttpStatusCode.Found)
            {
                if (dangNhapResponse.ResponseUri != null &&
                    dangNhapResponse.ResponseUri.Query != null &&
                    dangNhapResponse.ResponseUri.Query.Contains("user="******"Đang nhập thành công";
            }
            else
            {
                tk.TrangThai = "Đang nhập thất bại";
            }

            var    guiTin  = RequestToWeb.POST(new Uri("http://likeyou.vn/messages/send-message"), tk.Cookie, "fuid=636691&tuid=636421&message=Không có id người gửi", false);
            string s3      = Uri.UnescapeDataString(RequestToWeb.ReadStream(guiTin));
            var    header3 = RequestToWeb.ReadHeader(guiTin.Headers);
        }
Ejemplo n.º 6
0
        public static void Test()
        {
            ThongTinTaiKhoan tk = new ThongTinTaiKhoan();

            tk.TaiKhoan = "ngochoaitn";
            tk.MatKhau  = "noongngocj";

            tk.Cookie = new CookieContainer();
            string dangNhap_data = string.Format("username={0}&password={1}&nonxpcookie=1&login=Login&islogin=1",
                                                 tk.TaiKhoan, tk.MatKhau);
            var    dangNhap_Response = RequestToWeb.POST(new Uri("http://www.timbangai.com/timbangai/account/login/"), tk.Cookie, dangNhap_data, false);
            string dangNhap_string   = RequestToWeb.ReadStream(dangNhap_Response);
            var    dangNhap_Header   = RequestToWeb.ReadHeader(dangNhap_Response.Headers);

            if (dangNhap_string == "")
            {
                tk.TrangThai = "Đang nhập thành công";
            }
            else
            {
                tk.TrangThai = "Sai tài khoản hoặc mật khẩu";
            }


            //Gửi thư
            ThongTinTaiKhoan nguoigui  = tk;
            ThongTinTaiKhoan nguoinhan = new ThongTinTaiKhoan()
            {
                TenHienThi = "asbirine", Url = "http://www.timbangai.com/timbangai/asbirine"
            };

            if (string.IsNullOrEmpty(tk.Id))
            {
                //Lấy thông tin tài khoản nhận thư
                var    thongTinNguoiNhanThu_Response  = RequestToWeb.GET(new Uri(nguoinhan.Url), false);
                string thongTinNguoiNhanThu_string    = RequestToWeb.ReadStream(thongTinNguoiNhanThu_Response);
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(thongTinNguoiNhanThu_string);
                var    thongTinNguoiNhanThu_message = document.DocumentNode.Descendants("li").Where(div => div.HasClass("message")).FirstOrDefault();
                string thongTinNguoiNhanThu_Url     = thongTinNguoiNhanThu_message.QuerySelector("a").GetAttributeValue("href", "");
                nguoinhan.Id = thongTinNguoiNhanThu_Url.Split('/')[7];
            }
            string noidung         = "Nội dung tự động";
            string chude           = "chủ đề tự động";
            string guiThu_data     = string.Format("subject={0}&body={1}&submit=Gởi&ismessage=1", chude, noidung);
            var    guiThu_Response = RequestToWeb.POST(new Uri(string.Format("http://www.timbangai.com/timbangai/account/messages/compose/{0}", nguoinhan.Id)), nguoigui.Cookie, guiThu_data, false);
            string guiThu_string   = RequestToWeb.ReadStream(guiThu_Response);

            if (guiThu_string == "")
            {
                nguoinhan.TrangThai = tk.TaiKhoan;
            }
            else
            {
                nguoinhan.TrangThai = "Gửi lỗi";
            }
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <ThongTinTaiKhoan> > TimKiemAll(ThongTinTimKiem param)
        {
            Log.WriteLog(_fileLog, "Bắt đầu tìm kiếm ehenho...");
            List <ThongTinTaiKhoan> res = new List <ThongTinTaiKhoan>();
            int          pageindex      = 1;
            HtmlDocument document       = new HtmlDocument();
            string       linkNoiO       = $"https://www.ehenho.com{param.NoiO}";// $"https://www.ehenho.com{tinhtrang.Id}";
            int          countTry       = 0;

            while (true)
            {
                try
                {
                    Debug.WriteLine($"Trang {pageindex}----------------------------------");
                    Log.WriteLog(_fileLog, $"Trang {pageindex}----------------------------------");
                    HttpWebResponse response = RequestToWeb.GET(new Uri(linkNoiO), false, true, this.Cookie) as HttpWebResponse;
                    string          htmlText = RequestToWeb.ReadStream(response.GetResponseStream());
                    document.LoadHtml(htmlText);

                    var bangKetQua = document.DocumentNode.QuerySelectorAll("#pro_info");//
                    res.AddRange(await Task.WhenAll(bangKetQua.Select(p => TimKiemTaiKhoan(param, p))));

                    TimThayKetQua?.Invoke(res.Where(p => p != null));

                    //Tạo link trang tiếp
                    if (htmlText.Contains($"?page={pageindex + 1}"))
                    {
                        linkNoiO = $"https://www.ehenho.com{param.NoiO}?page={++pageindex}";
                    }
                    else if (htmlText.Contains($"?trang={pageindex + 1}"))
                    {
                        linkNoiO = $"https://www.ehenho.com{param.NoiO}?trang={++pageindex}";
                    }
                    else
                    {
                        break;
                    }

                    if (param.DungTimKiem)
                    {
                        break;
                    }
                    countTry = 0;
                }
                catch (Exception ex)
                {
                    if (countTry++ >= 20)
                    {
                        break;
                    }
                    Log.WriteLog(_fileLog, $"Lỗi {ex.Message}\r\n{ex.StackTrace}");
                }
            }
            Debug.WriteLine($"Kết thúc tìm kiếm tại {param.NoiO}, trang {pageindex}");
            Log.WriteLog(_fileLog, $"Kết thúc tìm kiếm tại {param.NoiO}, trang {pageindex}");
            return(res);
        }
Ejemplo n.º 8
0
        public static void Test()
        {
            #region Đang nhập, gửi tin
            ThongTinTaiKhoan tk = new ThongTinTaiKhoan();
            tk.Cookie   = new CookieContainer();
            tk.TaiKhoan = "ngochoaitn";
            tk.MatKhau  = "noongngocj";

            string dangNhapData           = string.Format("username={0}&password={1}&btn_submit=ĐĂNG NHẬP", tk.TaiKhoan, tk.MatKhau);
            var    dangNhapResponse       = RequestToWeb.POST(new Uri("https://henhoketban.vn/login.php"), tk.Cookie, dangNhapData, false);
            string dangNhapStringResponse = RequestToWeb.ReadStream(dangNhapResponse);
            var    dangNhapHeader         = RequestToWeb.ReadHeader(dangNhapResponse.Headers);
            if (dangNhapStringResponse.Contains("ĐĂNG NHẬP THÀNH CÔNG"))
            {
                //Đi lấy thông tin tài khoản
                var    layThongTinResponse       = RequestToWeb.GET(new Uri("https://henhoketban.vn/index.php"), false, false, tk.Cookie);
                string layThongTinStringResponse = RequestToWeb.ReadStream(layThongTinResponse);

                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(layThongTinStringResponse);

                string duongDan = document.DocumentNode.QuerySelectorAll("div#top > div > div > font > a").FirstOrDefault().GetAttributeValue("href", "");
                tk.Id = duongDan.Split('=')[1];

                //Lấy tên hiển thị
                var    tenHienThiResponse       = RequestToWeb.GET(new Uri(duongDan), false);
                string tenHienThiStringResponse = RequestToWeb.ReadStream(tenHienThiResponse);
                document.LoadHtml(tenHienThiStringResponse);
                tk.TenHienThi = document.DocumentNode.QuerySelector("h1 > font").InnerText.Split('|')[1].Trim();


                //Gửi tin nhắn
                ThongTinTaiKhoan tknhan = new ThongTinTaiKhoan()
                {
                    Id = "10454", TenHienThi = "Lan"
                };
                string tieuDe  = "Tiêu đề xxxxxxxx";
                string noidung = "Nội dung xxxxxxxxx";

                string guiData = string.Format("idgui={0}&idnhan={1}&tennguoigui={2}&tennguoinhan=AutoSend->{3}&tieude={4}&noidung={5}&btn_submit=GỬI TIN NHẮN",
                                               tk.Id, tknhan.Id, tk.TenHienThi, tknhan.TenHienThi, tieuDe, noidung);
                var    guiTinResponse    = RequestToWeb.POST(new Uri("https://henhoketban.vn/guithu.php"), tk.Cookie, guiData, false);
                string guiStringResponse = RequestToWeb.ReadStream(guiTinResponse);
                if (guiStringResponse.Contains("GỬI TIN NHẮN THÀNH CÔNG."))
                {
                    tknhan.TrangThai = tk.TaiKhoan;
                }
                else
                {
                    tknhan.TrangThai = "Gửi lỗi";
                }
            }
            #endregion
        }
Ejemplo n.º 9
0
        public DanhSachDuLieuTimKiem TaoDuLieuTimKiem()
        {
            //try
            //{
            DanhSachDuLieuTimKiem res = new DanhSachDuLieuTimKiem();

            //HttpWebResponse resposne = RequestToWeb.GET(new Uri("https://www.ehenho.com/tim-ban-cac-noi-o-chinh/"), false, true, Cookie) as HttpWebResponse;
            HttpWebResponse resposne = RequestToWeb.GET(new Uri("https://www.ehenho.com/tim-ban-bon-phuong-theo-noi-o/"), false, true, Cookie) as HttpWebResponse;
            HtmlDocument    document = new HtmlDocument();

            document.LoadHtml(RequestToWeb.ReadStream(resposne.GetResponseStream()));
            foreach (HtmlNode node in document.DocumentNode.QuerySelectorAll("a").Where(p => p.OuterHtml.Contains("/tim-ban-bon-phuong/")))
            {
                try { res.NoiO.Add(node.GetAttributeValue("href", ""), node.InnerText?.Replace("Tìm bạn ", "")?.Replace(",", "")?.Replace("&nbsp;", "")); }
                catch { }
            }

            res.TinhTrangHonNhan.Add(new ThongTinTimKiem.TinhTrangHonNhan()
            {
                Id = "/tim-ban-ban-phuong/", TenTinhTrang = "Tất cả"
            });
            res.TinhTrangHonNhan.Add(new ThongTinTimKiem.TinhTrangHonNhan()
            {
                Id = "/tim-ban-doc-than/", TenTinhTrang = "Độc thân"
            });
            res.TinhTrangHonNhan.Add(new ThongTinTimKiem.TinhTrangHonNhan()
            {
                Id = "/tim-ban-ly-di/", TenTinhTrang = "Ly dị"
            });
            res.TinhTrangHonNhan.Add(new ThongTinTimKiem.TinhTrangHonNhan()
            {
                Id = "/tim-ban-o-goa/", TenTinhTrang = "Ở góa"
            });
            res.TinhTrangHonNhan.Add(new ThongTinTimKiem.TinhTrangHonNhan()
            {
                Id = "/dang-co-nguoi-yeu-tim-ban/", TenTinhTrang = "Đang có người yêu"
            });

            res.GioiTinh.Add("Tất cả", "Tất cả");
            res.GioiTinh.Add("Nam", "Nam");
            res.GioiTinh.Add("Nữ", "Nữ");

            return(res);
            //}
            //catch(Exception ex)
            //{
            //    Log.WriteLog(_fileLog, $"Lỗi TaoDuLieuTimKiem() {ex.Message}\r\n{ex.ReadAllStatcktrace()}\r\n--------------------------------");
            //    throw new Exception("Không tạo được dữ liệu tìm kiếm");
            //}
        }
Ejemplo n.º 10
0
        public void DangNhap(ref ThongTinTaiKhoan tk)
        {
            tk.Cookie = new CookieContainer();
            string dangNhapData           = string.Format("username={0}&password={1}&btn_submit=ĐĂNG NHẬP", tk.TaiKhoan, tk.MatKhau);
            var    dangNhapResponse       = RequestToWeb.POST(new Uri("https://henhoketban.vn/login.php"), tk.Cookie, dangNhapData, false);
            string dangNhapStringResponse = RequestToWeb.ReadStream(dangNhapResponse);
            var    dangNhapHeader         = RequestToWeb.ReadHeader(dangNhapResponse.Headers);

            if (dangNhapStringResponse?.Contains("ĐĂNG NHẬP THÀNH CÔNG") ?? false)
            {
                tk.TrangThai      = "Đăng nhập thành công";
                tk.ChoPhepGuiNhan = true;
                #region Lấy Id, tên hiển thị dùng để gửi thư
                try
                {
                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();

                    #region Lấy ID
                    var    layThongTin_Id_Response   = RequestToWeb.GET(new Uri("https://henhoketban.vn/index.php"), false, false, tk.Cookie);
                    string layThongTinStringResponse = RequestToWeb.ReadStream(layThongTin_Id_Response);

                    document.LoadHtml(layThongTinStringResponse);

                    string duongDan = document.DocumentNode.QuerySelectorAll("div#top > div > div > font > a").FirstOrDefault().GetAttributeValue("href", "");
                    tk.Id  = duongDan.Split('=')[1];
                    tk.Url = duongDan;
                    #endregion

                    #region Lấy tên hiển thị
                    var    tenHienThi_Response      = RequestToWeb.GET(new Uri(duongDan), false);
                    string tenHienThiStringResponse = RequestToWeb.ReadStream(tenHienThi_Response);
                    document.LoadHtml(tenHienThiStringResponse);
                    tk.TenHienThi = document.DocumentNode.QuerySelector("h1 > font").InnerText.Split('|')[1].Trim();
                    #endregion
                }
                catch
                { }
                #endregion
            }
        }
Ejemplo n.º 11
0
        public void GuiTin(ThongTinTaiKhoan nguoigui, ThongTinTaiKhoan nguoinhan, string tieude, string noidung, Action <string> callback = null)
        {
            HttpWebResponse response = RequestToWeb.GET(new Uri(nguoinhan.Url), false, true, nguoigui.Cookie) as HttpWebResponse;
            string          htmlText = RequestToWeb.ReadStream(response.GetResponseStream());

            if (htmlText.Contains("class=\"msg-cp\""))
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(htmlText);
                var    csrfmiddlewaretoken = document.DocumentNode.SelectSingleNode("//input[@type='hidden' and @name='csrfmiddlewaretoken']").Attributes["value"].Value;
                string data         = $"csrfmiddlewaretoken={csrfmiddlewaretoken}&body={noidung}&send=      Gửi!      ";
                string responseHtml = RequestToWeb.ReadStream(RequestToWeb.POST(new Uri(nguoinhan.Url), nguoigui.Cookie, data, false, true,
                                                                                config_more: (request) =>
                {
                    request.Accept  = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
                    request.Referer = nguoinhan.Url;
                }));

                if (responseHtml == null)
                {
                    nguoinhan.TrangThai     = nguoigui.TrangThai = "Gửi lỗi\r\nKhông đọc được nội dung";
                    nguoigui.ChoPhepGuiNhan = false;
                    nguoinhan.TrangThai     = "Gửi lỗi (Web không trả về dữ liệu để xử lý)";
                }
                else if (responseHtml?.Contains("Thư gửi không thành công!") ?? true)
                {
                    nguoinhan.TrangThai     = nguoigui.TrangThai = "Gửi lỗi\nQuá giới hạn 48 thư";
                    nguoigui.ChoPhepGuiNhan = false;
                }
                else
                {
                    nguoinhan.TrangThai = nguoigui.TaiKhoan;
                }
            }
            else
            {
                nguoinhan.TrangThai     = nguoigui.TrangThai = "Gửi lỗi. Tài khoản bị khóa";
                nguoigui.ChoPhepGuiNhan = false;
            }
        }
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            HtmlDocument doc = new HtmlDocument();

            foreach (var cm in param.ChuyenMucs)
            {
                string url  = $"{cm.UrlChuyenMuc}?sort=dateline&order=desc";
                string html = RequestToWeb.GET(new Uri(url), false, true, this.Cookie).ReadStream();
                doc.LoadHtml(html);
                var threads = doc.GetElementbyId("threads").QuerySelectorAll("li");
                foreach (var thread in threads)
                {
                    var ctn_auTypPost = thread.QuerySelectorAll("div > div > div > ul > li");
                    if (ctn_auTypPost.Count() > 2)
                    {
                        var nameAuPost = ctn_auTypPost.ElementAt(0);// thread.QuerySelector("div > div > div > ul > li");
                        if (nameAuPost != null)
                        {
                            yield return(new ThongTinTaiKhoan()
                            {
                                Id = nameAuPost.InnerHtml.Substring("?u=", "')"),
                                TaiKhoan = nameAuPost.InnerText,
                            });

                            if (param.TimNguoiMoiBinhLuan)
                            {
                                var newRplSub = ctn_auTypPost.ElementAt(1);
                                yield return(new ThongTinTaiKhoan()
                                {
                                    Id = newRplSub.InnerHtml.Substring("?u=", "&amp"),
                                    TaiKhoan = newRplSub.QuerySelector("strong")?.InnerText,
                                });
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            #region Tạo request
            NameValueCollection formData = new NameValueCollection();
            formData.Add("type_id", "members");
            formData.Add("gender2", "1");
            formData.Add("gender1", param.GioiTinh.ToString());
            formData.Add("age_from", param.TuTuoi.ToString());
            formData.Add("age_to", param.DenTuoi.ToString());
            formData.Add("country", "212");
            formData.Add("city", param.NoiO.ToString());
            if (param.HonNhan.FirstOrDefault().Id.ToString() != "-1")
            {
                formData.Add("livingsituation[]", string.Format("{0}", string.Join("&livingsituation[]=", param.HonNhan.Select(p => p.Id.ToString()))));
            }
            formData.Add("username", "");
            formData.Add("online_only", "0");
            formData.Add("pictures_only", "0");
            formData.Add("display_type", "1");
            formData.Add("search_save", "");
            formData.Add("submit", "Gởi");
            formData.Add("issearch", "1");

            string timKiem_data     = formData.ConvertToUrlEncode();
            var    timKiem_Response = RequestToWeb.POST(new Uri("http://www.timbangai.com/timbangai/search/advanced/"), null, timKiem_data, false, false);
            var    headers          = RequestToWeb.ReadHeader(timKiem_Response);
            string timKiem_string   = RequestToWeb.ReadStream(timKiem_Response);
            string timKiem_location = timKiem_Response.Headers[HttpResponseHeader.Location];
            #endregion

            if ((timKiem_Response as HttpWebResponse).StatusCode == HttpStatusCode.Found)
            {
                int page = 1;
                while (true)
                {
                    string timKiem_link = string.Format("{0}{1}", timKiem_location, page);
                    timKiem_Response = RequestToWeb.GET(new Uri(timKiem_link), false);
                    timKiem_string   = RequestToWeb.ReadStream(timKiem_Response);

                    //string timKiem_string = File.ReadAllText("DataHtmlTest.txt");
                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(HttpUtility.HtmlDecode(timKiem_string));

                    var bangKetQua     = document.DocumentNode.QuerySelectorAll("div#content").FirstOrDefault();
                    var danhSachKetQua = bangKetQua.Descendants("div").Where(div => div.HasClass("image"));
                    if (danhSachKetQua.Count() == 0)
                    {
                        break;
                    }
                    foreach (var kq in danhSachKetQua)
                    {
                        ThongTinTaiKhoan tk = new ThongTinTaiKhoan();

                        var ten_tuoi = kq.InnerText.Trim().Split(',');
                        tk.TenHienThi       = ten_tuoi[0];
                        tk.Tuoi             = ten_tuoi[ten_tuoi.Count() - 1].ConvertToInt32();
                        tk.Url              = kq.QuerySelector("a").GetAttributeValue("href", "");
                        tk.GioiTinh         = param.OtherParam[0].ToString();
                        tk.TinhTrangHonNhan = param.OtherParam[1].ToString();
                        #region Lấy ID
                        Task.Run(
                            () =>
                        {
                            var thongTinNguoiNhanThu_Response = RequestToWeb.GET(new Uri(tk.Url), false);

                            string thongTinNguoiNhanThu_string = RequestToWeb.ReadStream(thongTinNguoiNhanThu_Response);
                            HtmlAgilityPack.HtmlDocument thongTinNguoiNhanThu_document = new HtmlAgilityPack.HtmlDocument();
                            if (!string.IsNullOrEmpty(thongTinNguoiNhanThu_string))
                            {
                                thongTinNguoiNhanThu_document.LoadHtml(thongTinNguoiNhanThu_string);

                                var thongTinNguoiNhanThu_message = thongTinNguoiNhanThu_document.DocumentNode.Descendants("li").Where(div => div.HasClass("message")).FirstOrDefault();
                                string thongTinNguoiNhanThu_Url  = thongTinNguoiNhanThu_message.QuerySelector("a").GetAttributeValue("href", "");
                                tk.Id = thongTinNguoiNhanThu_Url.Split('/')[7];
                            }
                        });
                        #endregion
                        yield return(tk);

                        if (param.DungTimKiem)
                        {
                            break;
                        }
                    }
                    if (param.DungTimKiem)
                    {
                        break;
                    }
                    page++;
                }
            }
        }
Ejemplo n.º 14
0
        public void DangNhap(ref ThongTinTaiKhoan tk)
        {
            #region Logout
            ////Https nên có xác thực => nếu không đăng xuất sẽ bị lấy phiên đăng nhập cũ
            //HttpWebRequest logoutRequest = WebRequest.CreateHttp("https://www.vietnamcupid.com/vi/auth/logout");
            //logoutRequest.Method = "GET";
            //var logoutResponse = RequestToWeb.GET(new Uri("https://www.vietnamcupid.com/vi/auth/logout"), true);
            #endregion

            #region Login
            tk.Cookie = new CookieContainer();

            #region Login 1: Get first Cookie, Parameter
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
            client.DefaultRequestHeaders.Add("Accept-Language", "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5");
            client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");

            client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/78.0.136 Chrome/72.0.3626.136 Safari/537.36");
            var x = client.GetAsync("https://www.vietnamcupid.com/en/auth/login").Result.ReadStringAsync().Result;

            var loginResponse = RequestToWeb.GET(new Uri("https://www.vietnamcupid.com/en/auth/login"), false, true, tk.Cookie,
                                                 (req) =>
            {
                //req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
                req.Headers.Add(HttpRequestHeader.AcceptLanguage, "vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5");
                req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            });
            var loginPageHtml = RequestToWeb.ReadStream(loginResponse);
            HtmlAgilityPack.HtmlDocument docLogin = new HtmlAgilityPack.HtmlDocument();
            docLogin.LoadHtml(loginPageHtml);
            var formLogin = docLogin.DocumentNode.QuerySelector("form > input");
            #endregion Login 1: Get first Cookie

            #region Login 2: Get login cookie
            string ioBB = docLogin.GetElementbyId("ioBB").GetAttributeValue("value", "");
            string mht  = docLogin.DocumentNode.SelectSingleNode("//input[@type='hidden' and @name='mht']").Attributes["value"].Value;

            string loginData      = $"mht={mht}&page=&email={tk.TaiKhoan}&password={tk.MatKhau}&RememberMe=on&ioBB={ioBB}";
            var    loginResponse2 = RequestToWeb.POST(new Uri("https://www.vietnamcupid.com/logon_do.cfm"), tk.Cookie, loginData, true);// loginRequest2.GetResponse();

            string sLoginCookie2 = loginResponse2.Headers[HttpResponseHeader.SetCookie];
            string sLoginLoc2    = loginResponse2.Headers[HttpResponseHeader.Location];
            tk.TrangThai      = "Đang nhập thành công";
            tk.ChoPhepGuiNhan = true;
            if (sLoginLoc2.Contains("error"))
            {
                tk.TrangThai      = "Sai tài khoản hoặc mật khẩu";
                tk.Cookie         = null;
                tk.ChoPhepGuiNhan = false;
            }
            //Https chưa lưu được cookie
            //else
            //{
            //    foreach (Cookie cook in tk.Cookie.GetCookies(UriTrangWeb.VietNamCupid))
            //    {
            //        if (cook.Name == "_DIST")
            //        {
            //            tk.HanCookie = cook.Expires;
            //        }
            //    }
            //}

            #endregion Login 2: Get login cookie

            #endregion
        }
Ejemplo n.º 15
0
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            int pageindex = 1;

            while (true)
            {
                #region Tạo reqeuest
                var         uri = new UriBuilder("https://www.vietnamcupid.com/");
                WebResponse response;
                if (pageindex == 1)
                {
                    uri = new UriBuilder("https://www.vietnamcupid.com/vi/results/search?searchtype=1");
                    string data = string.Format("resulttype=advanced&gender_w={0}&age_min={1}&age_max={2}", param.GioiTinh, param.TuTuoi, param.DenTuoi);
                    data += string.Format("&countryLive=230&stateLive={0}", param.NoiO);
                    foreach (var hn in param.HonNhan)
                    {
                        data += string.Format("&maritalStatus={0}", hn.Id);
                    }
                    data    += "&cityLive=-1&searchingFor=-1&resetCurrency=VND&distanceUnit=kms&gender=254";
                    response = RequestToWeb.POST(uri.Uri, this.Cookie, data, false, true);
                }
                else
                {
                    uri      = new UriBuilder(string.Format("https://www.vietnamcupid.com/vi/results/search?pageno={0}", pageindex));
                    response = RequestToWeb.GET(uri.Uri, false, false, this.Cookie);
                }
                #endregion

                #region Lấy dữ liệu
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string content = sr.ReadToEnd();
                    //string content = File.ReadAllText("DataHtmlTest.txt");
                    content = HttpUtility.HtmlDecode(content);

                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(content);

                    var bangKetQua = document.DocumentNode.QuerySelectorAll("div#memberships > div").ToList();
                    for (int i = 0; i < bangKetQua.Count; i++)
                    {
                        ThongTinTaiKhoan taiKhoan = new ThongTinTaiKhoan();
                        var memberpicgeneric      = bangKetQua[i].QuerySelectorAll("div > div > p");
                        if (memberpicgeneric.Count() < 2)
                        {
                            continue;//Quảng cáo
                        }
                        var hdg1 = memberpicgeneric.ElementAt(0).QuerySelector("a");
                        var hdg2 = memberpicgeneric.ElementAt(1);
                        if (memberpicgeneric != null)
                        {
                            string duongDan = hdg1.GetAttributeValue("href", "");
                            if (!string.IsNullOrEmpty(duongDan))
                            {
                                try
                                {
                                    var    tmpUri  = new Uri("https://www.vietnamcupid.com" + duongDan);
                                    string id      = tmpUri.Segments[tmpUri.Segments.Count() - 1];
                                    var    tenTuoi = hdg1.InnerHtml.Split('(', ')').Where(p => !string.IsNullOrEmpty(p)).ToList();
                                    string ten     = tenTuoi[0];
                                    string tuoi    = tenTuoi[tenTuoi.Count - 1];//lấy tuổi cuối cùng

                                    string noiO = "";
                                    if (hdg2.ChildNodes.Count >= 1)
                                    {
                                        noiO = hdg2.ChildNodes[1].InnerText.TrimAll();
                                    }
                                    else
                                    {
                                        try
                                        {
                                            var tmp = bangKetQua[i].QuerySelectorAll("div > div").FirstOrDefault();
                                            noiO = tmp.ChildNodes[2].InnerText.TrimAll();
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    taiKhoan.Url              = string.Format("https://www.vietnamcupid.com/vi/profile/showProfile/ID/{0}", id);
                                    taiKhoan.Id               = id;
                                    taiKhoan.TenHienThi       = ten.Trim();
                                    taiKhoan.ChoPhepGuiNhan   = true;
                                    taiKhoan.Tuoi             = tuoi.ConvertToInt32();
                                    taiKhoan.GioiTinh         = param.OtherParam[0].ToString();
                                    taiKhoan.NoiO             = noiO;
                                    taiKhoan.TinhTrangHonNhan = param.OtherParam[1].ToString();
                                }
                                catch//(Exception ex)
                                { taiKhoan = null; }

                                if (taiKhoan != null)
                                {
                                    yield return(taiKhoan);
                                }

                                if (param.DungTimKiem)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    //Test: break;
                    if (bangKetQua.Count <= 1)
                    {
                        break;
                    }
                }
                #endregion

                if (param.DungTimKiem)
                {
                    break;
                }

                pageindex++;
            }
        }
Ejemplo n.º 16
0
        public static void Test()
        {
            #region Logout
            RequestToWeb.GET(new Uri("https://badoo.com/profile/logout"), true);
            //HttpWebRequest logoutRequest = WebRequest.CreateHttp("https://badoo.com/profile/logout");
            //logoutRequest.Method = "GET";
            //var logoutResponse = logoutRequest.GetResponse();
            #endregion

            #region Login
            CookieContainer loginCookie   = new CookieContainer();
            HttpWebRequest  loginRequest1 = WebRequest.CreateHttp("https://badoo.com/signin");

            loginRequest1.CookieContainer   = loginCookie;
            loginRequest1.Method            = "GET";
            loginRequest1.AllowAutoRedirect = true;
            loginRequest1.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/64.4.142 Chrome/58.4.3029.142 Safari/537.36";
            loginRequest1.Accept            = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            //loginRequest1.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, sdch, br");
            loginRequest1.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8,vi;q=0.6");
            loginRequest1.KeepAlive = true;
            loginRequest1.Headers.Add("DNT", "1");
            loginRequest1.Headers.Add("Upgrade-Insecure-Requests", "1");
            //using (StreamWriter sw = new StreamWriter(loginRequest1.GetRequestStream()))
            //{
            //    string data = File.ReadAllLines("DataHtmlTest.txt")[0];
            //    sw.Write(data);
            //    sw.Close();
            //}
            var loginRequest1Header = RequestToWeb.ReadHeader(loginRequest1.Headers);

            var loginResponse1 = loginRequest1.GetResponse();

            string sLoginCookie = loginResponse1.Headers[HttpResponseHeader.SetCookie];
            string sCookie1     = loginRequest1.Headers[HttpRequestHeader.Cookie];
            string sLoginLoc1   = loginResponse1.Headers[HttpResponseHeader.Location];

            var loginHeader1 = RequestToWeb.ReadHeader(loginResponse1.Headers);

            string logginS1 = "";
            using (StreamReader sr = new StreamReader(loginResponse1.GetResponseStream()))
            {
                logginS1 = sr.ReadToEnd();
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Bước 2

            HttpWebRequest loginRequestB2 = WebRequest.CreateHttp("https://badoo.com/api.phtml?SERVER_APP_STARTUP");

            loginRequestB2.CookieContainer   = loginCookie;
            loginRequestB2.Method            = "POST";
            loginRequestB2.AllowAutoRedirect = true;
            loginRequestB2.ContentType       = "json";
            loginRequestB2.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/64.4.142 Chrome/58.4.3029.142 Safari/537.36";
            loginRequestB2.KeepAlive         = true;
            //loginRequest2.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            loginRequestB2.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8,vi;q=0.6");
            loginRequestB2.Referer = "https://badoo.com/signin";
            loginRequestB2.Headers.Add("X-Session-id", sLoginCookie.Split(new string[] { "s2=", ";" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            loginRequestB2.Headers.Add("X-Message-type:2");

            int    indexIfDeviceId = sLoginCookie.IndexOf("device_id");
            string deviceId        = sLoginCookie.Substring(indexIfDeviceId);
            deviceId = deviceId.Substring(10);
            deviceId = deviceId.Substring(0, deviceId.IndexOf(";"));

            using (StreamWriter sw = new StreamWriter(loginRequestB2.GetRequestStream()))
            {
                string data = File.ReadAllLines("BadooTest.txt")[1].Replace("_DEVICEID_", deviceId);
                sw.Write(data);
                sw.Close();
            }

            var loginResponseB2 = loginRequestB2.GetResponse();

            string sLoginCookieB2 = loginResponseB2.Headers[HttpResponseHeader.SetCookie];
            string sCookieB2      = loginRequestB2.Headers[HttpRequestHeader.Cookie];
            string sLoginLocB2    = loginResponseB2.Headers[HttpResponseHeader.Location];

            var loginHeaderB2 = RequestToWeb.ReadHeader(loginResponseB2.Headers);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////LẦN 2
            HttpWebRequest loginRequest2 = WebRequest.CreateHttp("https://badoo.com/api.phtml?SERVER_LOGIN_BY_PASSWORD");

            loginRequest2.CookieContainer   = loginCookie;
            loginRequest2.Method            = "POST";
            loginRequest2.AllowAutoRedirect = true;
            loginRequest2.ContentType       = "json";
            loginRequest2.UserAgent         = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/64.4.142 Chrome/58.4.3029.142 Safari/537.36";
            loginRequest2.KeepAlive         = true;
            //loginRequest2.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            loginRequest2.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8,vi;q=0.6");
            loginRequest2.Referer = "https://badoo.com/signin";
            loginRequest2.Headers.Add("X-Session-id", sLoginCookie.Split(new string[] { "s2=", ";" }, StringSplitOptions.RemoveEmptyEntries)[0]);
            //loginRequest2.Headers.Add("X-Message-type:15");

            using (StreamWriter sw = new StreamWriter(loginRequest2.GetRequestStream()))
            {
                string data = File.ReadAllLines("BadooTest.txt")[0];
                sw.Write(data);
                sw.Close();
            }

            var loginResponse2 = loginRequest2.GetResponse();

            string sLoginCookie2 = loginResponse2.Headers[HttpResponseHeader.SetCookie];
            string sCookie2      = loginRequest2.Headers[HttpRequestHeader.Cookie];
            string sLoginLoc2    = loginResponse2.Headers[HttpResponseHeader.Location];

            var loginHeader2 = RequestToWeb.ReadHeader(loginResponse2.Headers);

            string logginS2 = "";
            using (StreamReader sr = new StreamReader(loginResponse2.GetResponseStream()))
            {
                logginS2 = sr.ReadToEnd();
                sr.Close();//Đã ok đến đây
            }
            #endregion

            #region Search

            #endregion
        }
Ejemplo n.º 17
0
        private Task <ThongTinTaiKhoan> TimKiemTaiKhoan(ThongTinTimKiem param, HtmlNode kq)
        {
            return(Task.Run <ThongTinTaiKhoan>(() =>
            {
                ThongTinTaiKhoan tk = new ThongTinTaiKhoan();
                try
                {
                    string log = $"{DateTime.Now.ToString("HH:mm:ss")} -> ";

                    var thongTinKq = kq.QuerySelector("p");
                    var spanKq = thongTinKq?.QuerySelectorAll("span");

                    var ten_tuoi_tinhTrang = spanKq.ElementAt(0);

                    var ten_tuoi_tinh_trang_a = ten_tuoi_tinhTrang?.QuerySelectorAll("a");

                    var ten = ten_tuoi_tinh_trang_a.ElementAt(0);
                    tk.TenHienThi = ten.InnerText;
                    tk.Url = $"https://www.ehenho.com{ten.GetAttributeValue("href", "")}";
                    tk.Id = tk.Url?.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries)?.Last();
                    tk.Tuoi = ten_tuoi_tinhTrang.InnerText.Split(new[] { "&nbsp;" }, StringSplitOptions.RemoveEmptyEntries)?.ElementAt(1)?.Trim()?.ConvertToInt32();
                    if (string.IsNullOrEmpty(tk.Id) || tk.Tuoi == null || tk.Tuoi > param.DenTuoi || tk.Tuoi < param.TuTuoi)
                    {
                        Debug.WriteLine($"{log}{DateTime.Now.ToString("HH:mm:ss")} Faild (không đủ tuổi: {tk.Tuoi})");
                        return null;
                    }

                    #region Tỉnh trạng hôn nhân
                    tk.TinhTrangHonNhan = ten_tuoi_tinh_trang_a.ElementAt(1)?.InnerText;
                    if (!param.HonNhan.Select(p => p.TenTinhTrang).Contains("Tất cả") && !param.HonNhan.Select(p => p.Id).Contains(ten_tuoi_tinh_trang_a.ElementAt(1).GetAttributeValue("href", "")))
                    {
                        if (tk.GioiTinh != param.GioiTinh.ToString())
                        {
                            Debug.WriteLine($"{log}{DateTime.Now.ToString("HH:mm:ss")} Faild (Tình trạng hôn nhân: {tk.TinhTrangHonNhan})");
                            return null;
                        }
                    }
                    #endregion Tình trạng hôn nhân

                    #region Nơi ở
                    var noiO = spanKq.ElementAt(1);
                    var noiO_a = noiO.QuerySelectorAll("a");
                    List <string> diaChi = new List <string>();
                    for (int i = 1; i < noiO_a.Count(); i++)
                    {
                        diaChi.Add(noiO_a.ElementAt(i).InnerText);
                    }
                    tk.NoiO = string.Join(", ", diaChi);
                    #endregion Nơi ở

                    #region Giới tính (có thể lấy thông tin qua cách này luôn cho dễ với đầy đủ)
                    tk.GioiTinh = "Tất cả";
                    if (param.GioiTinh.ToString() != "Tất cả" || param.ThoiGianDangNhap.HasValue)
                    {
                        HtmlDocument docChiTiet = new HtmlDocument();
                        string html = RequestToWeb.ReadStream(RequestToWeb.GET(new Uri(tk.Url), false, true, this.Cookie));
                        int countTry = 0;
                        while (string.IsNullOrEmpty(html) && countTry++ < 3)
                        {
                            Log.WriteLog(_fileLog, $"TimKiemTaiKhoan() Thử lại {tk?.Url}");
                            html = RequestToWeb.ReadStream(RequestToWeb.GET(new Uri(tk.Url), false, true, this.Cookie));
                        }

                        if (string.IsNullOrEmpty(html))
                        {
                            return null;
                        }

                        docChiTiet.LoadHtml(html);
                        var allRow = docChiTiet?.DocumentNode?.QuerySelectorAll("table > tr");
                        if (param.GioiTinh.ToString() != "Tất cả")
                        {
                            tk.GioiTinh = allRow?.ElementAt(6)?.QuerySelectorAll("td")?.Last()?.InnerText?.Split(' ')?.First();
                            if (tk.GioiTinh != param.GioiTinh.ToString())
                            {
                                Debug.WriteLine($"{log}{DateTime.Now.ToString("HH:mm:ss")} Faild (Giới tính: {tk.GioiTinh})");
                                return null;
                            }
                        }

                        if (param.ThoiGianDangNhap.HasValue)
                        {
                            try
                            {
                                DateTime thoiGianDangNhapganNhat = Convert.ToDateTime(allRow?.ElementAt(allRow.Count() - 2)?.QuerySelectorAll("td")?.Last()?.InnerText?.Replace(".", ""));
                                if ((DateTime.Now - thoiGianDangNhapganNhat).TotalMinutes > param.ThoiGianDangNhap)
                                {
                                    Debug.WriteLine($"{log}{DateTime.Now.ToString("HH:mm:ss")} Faild (Thời gian đăng nhập: {thoiGianDangNhapganNhat.ToString("dd/MM/yyyy HH:mm")})");
                                    return null;
                                }
                            }
                            catch { }
                        }
                    }
                    #endregion Giới tính
                    Debug.WriteLine($"{log}{DateTime.Now.ToString("HH:mm:ss")} OK: {tk.Url}");
                    return tk;
                }
                catch (Exception ex)
                {
                    Log.WriteLog(_fileLog, $"Lỗi TimKiemTaiKhoan({tk?.Url}) {ex.Message}\r\n{ex.StackTrace}");
                    return null;
                }
            }));
        }
Ejemplo n.º 18
0
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            int page   = 1;
            int numTry = 0;

            while (true)
            {
                #region Tạo reqeuest
                var uri = new UriBuilder("http://likeyou.vn/vi/searchs");

                var query = HttpUtility.ParseQueryString(uri.Query);
                #region Giới tính
                switch (param.GioiTinh.ToString())
                {
                case "1": query["men"] = "1"; break;

                case "2": query["woman"] = "2"; break;

                case "-1": query["men"] = "1"; query["woman"] = "1"; break;
                }
                #endregion
                query["agefrom"] = param.TuTuoi.ToString();
                query["ageto"]   = param.DenTuoi.ToString();
                if (param.NoiO.ToString() != "-1")
                {
                    query["district"] = param.NoiO.ToString();
                }
                query["country"]      = "1";//Việt Nam;
                query["type"]         = "advanced";
                query["relationship"] = string.Join("-", param.HonNhan.Select(p => p.Id.ToString()));
                if (page >= 2)
                {
                    query["page"] = page.ToString();
                }

                uri.Query = query.ToString();
                var response = RequestToWeb.GET(uri.Uri, false);
                #endregion

                #region Lấy dữ liệu
                string sKQTimKiem = RequestToWeb.ReadStream(response);
                sKQTimKiem = HttpUtility.HtmlDecode(sKQTimKiem);
                if (string.IsNullOrEmpty(sKQTimKiem))
                {
                    if (numTry++ < 10)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(sKQTimKiem);

                var results_search2 = document.DocumentNode.Descendants("div").Where(div => div.HasClass("item-search-content-left"));
                if (results_search2.Count() < 1)
                {
                    break;
                }
                foreach (var v in results_search2)
                {
                    var    infousearchg = v.Descendants("div").Where(div => div.HasClass("infousearchg")).FirstOrDefault();
                    var    item_provice = v.Descendants("div").Where(div => div.HasClass("item-provice")).FirstOrDefault();
                    string link = infousearchg.QuerySelector("a").GetAttributeValue("href", "");
                    string id = link.Split('=')[1];
                    string tuoi = "", ten = "";
                    var    gioiTinh  = infousearchg.Descendants("i").FirstOrDefault();
                    string sGioiTinh = "";
                    if (gioiTinh != null && gioiTinh.GetAttributeValue("class", "") != null)
                    {
                        sGioiTinh = gioiTinh.GetAttributeValue("class", "");
                    }
                    if (infousearchg != null)
                    {
                        var ten_tuoi = infousearchg.InnerText.Split(',');
                        ten  = ten_tuoi[0].Trim();
                        tuoi = ten_tuoi[ten_tuoi.Count() - 1].Trim();
                    }
                    string noiO = item_provice.InnerText.Trim();

                    ThongTinTaiKhoan tk = new ThongTinTaiKhoan();
                    tk.Tuoi             = tuoi.ConvertToInt32();
                    tk.TenHienThi       = ten;
                    tk.NoiO             = noiO;
                    tk.GioiTinh         = sGioiTinh != "" ? (sGioiTinh == "men" ? "Nam" : "Nữ") : param.OtherParam[0].ToString();
                    tk.TinhTrangHonNhan = param.OtherParam[1].ToString();
                    tk.Url = link;
                    tk.Id  = id;

                    yield return(tk);

                    if (param.DungTimKiem)
                    {
                        break;
                    }
                }
                #endregion
                if (param.DungTimKiem)
                {
                    break;
                }
                page++;
            }
        }
Ejemplo n.º 19
0
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            Log.WriteLog(_fileLog, "Bắt đầu tìm kiếm henho2...");
            foreach (var tinhtrang in param.HonNhan)
            {
                int pageindex = 1;
                while (true)
                {
                    #region Tạo reqeuest
                    var uri   = new UriBuilder("https://henho2.com/Home/Index");
                    var query = HttpUtility.ParseQueryString(uri.Query);
                    query["gtinh"]     = param.GioiTinh.ToString();
                    query["countryid"] = "237";//Việt Nam
                    query["province"]  = param.NoiO.ToString();
                    query["maritial"]  = tinhtrang.Id.ToString();
                    query["objective"] = "-1";
                    query["ageFrom"]   = param.TuTuoi.ToString();
                    query["ageTo"]     = param.DenTuoi.ToString();
                    query["name"]      = "";
                    query["pageindex"] = pageindex.ToString();
                    uri.Query          = query.ToString();

                    Log.WriteLog(_fileLog, $"Truy vấn {uri.Uri.ToString()}");
                    var response = RequestToWeb.GET(uri.Uri, false);
                    //var response = RequestToWeb.GET(new Uri("http://localhost:8081/"), false);
                    #endregion
                    Log.WriteLog(_fileLog, $"Truy vấn xong {uri.Uri.ToString()}");
                    #region Lấy dữ liệu
                    //using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                    //{
                    string content = RequestToWeb.ReadStream(response); // sr.ReadToEnd();
                                                                        //content = File.ReadAllText("C:\\Users\\ngochoaitn\\Desktop\\new2.html");
                                                                        //content = HttpUtility.HtmlDecode(content);

                    if (content == null)
                    {
                        content = "";
                    }

                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(content);

                    //Bảng có 24 hàng, trong đó 20 hàng dữ liệu, 1 hàng header, 2 hàng quảng cáo, 1 hàng footer
                    var bangKetQua2 = document.DocumentNode.QuerySelectorAll("table > tbody > tr").ToList();
                    if (bangKetQua2 == null || bangKetQua2.Count <= 1)//hết dữ liệu
                    {
                        break;
                    }
                    Log.WriteLog(_fileLog, "Lấy bảng kết quả");
                    bool continueAll = true;
                    for (int i = 0; i < bangKetQua2.Count; i++)
                    {
                        var tableData = bangKetQua2[i].QuerySelectorAll("td");
                        if (tableData.Count() != 2)
                        {
                            continue;
                        }
                        continueAll = false;

                        var td1 = tableData.ElementAt(0);
                        var td2 = tableData.ElementAt(1);

                        ThongTinTaiKhoan taiKhoan = new ThongTinTaiKhoan();

                        var tenHienThi = td1.QuerySelector("a");
                        if (tenHienThi != null)
                        {
                            string duongDan = tenHienThi.GetAttributeValue("href", "");
                            if (!string.IsNullOrEmpty(duongDan))
                            {
                                try
                                {
                                    int      id = Convert.ToInt32(duongDan.Split('/')[3]);
                                    string[] ten_gioitinh_tuoi = td2.InnerText.Split('\n');
                                    string   ten      = td1.InnerText.Trim();
                                    string   gioiTinh = ten_gioitinh_tuoi[2]?.Trim();
                                    string   tuoi     = ten_gioitinh_tuoi[4].Trim().Replace(" -", "");

                                    taiKhoan.Url              = string.Format("https://henho2.com{0}", duongDan);
                                    taiKhoan.Id               = duongDan.Split('/')[3];
                                    taiKhoan.TenHienThi       = ten.Trim();
                                    taiKhoan.ChoPhepGuiNhan   = true;
                                    taiKhoan.Tuoi             = tuoi.ConvertToInt32();
                                    taiKhoan.GioiTinh         = gioiTinh;
                                    taiKhoan.NoiO             = ten_gioitinh_tuoi[12].Trim();
                                    taiKhoan.TinhTrangHonNhan = ten_gioitinh_tuoi[6].Trim();
                                    //Thời gian đăng nhập
                                    if (param.ThoiGianDangNhap.HasValue)
                                    {
                                        HtmlAgilityPack.HtmlDocument docThongTinCaNhan = new HtmlAgilityPack.HtmlDocument();
                                        var thongTinCaNhan = RequestToWeb.ReadStream(RequestToWeb.GET(new Uri(taiKhoan.Url), false));
                                        if (thongTinCaNhan != null)
                                        {
                                            docThongTinCaNhan.LoadHtml(thongTinCaNhan);
                                            var bangThongTin     = docThongTinCaNhan.DocumentNode.QuerySelectorAll("table > tbody > tr").ToList();
                                            var thoiGianDangNhap = bangThongTin?.FirstOrDefault(p => p.InnerText?.ToLower()?.Contains("đăng nhập") ?? false);
                                            if (thoiGianDangNhap != null && !string.IsNullOrEmpty(thoiGianDangNhap.InnerText))
                                            {
                                                try
                                                {
                                                    DateTime thoiGianDangNhapganNhat = Convert.ToDateTime(thoiGianDangNhap.InnerText.ToLower().Replace("đăng nhập", "").TrimAll());
                                                    if ((DateTime.Now - thoiGianDangNhapganNhat).TotalMinutes > param.ThoiGianDangNhap)
                                                    {
                                                        taiKhoan = null;
                                                    }
                                                }
                                                catch { }
                                            }
                                            else
                                            {
                                                taiKhoan = null;
                                            }
                                        }
                                        else
                                        {
                                            taiKhoan = null;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    taiKhoan = null;
                                    Log.WriteLog(_fileLog, $"Truy vấn xong {ex.Message}");
                                }

                                if (taiKhoan != null)
                                {
                                    yield return(taiKhoan);
                                }
                            }
                        }

                        if (param.DungTimKiem)
                        {
                            break;
                        }
                    }
                    if (continueAll)
                    {
                        break;
                    }

                    // }
                    #endregion
                    if (param.DungTimKiem)
                    {
                        break;
                    }
                    pageindex++;
                    Log.WriteLog(_fileLog, $"Next trang {pageindex}");
                }
            }
        }
Ejemplo n.º 20
0
        public IEnumerable <ThongTinTaiKhoan> TimKiem(ThongTinTimKiem param)
        {
            foreach (var hn in param.HonNhan)
            {
                int page = 1;
                while (true)
                {
                    #region Tạo reqeuest
                    string linkTimKiem = string.Format("?page={0}&gioitinh={1}&tuoi1={2}&tuoi2={3}&dentu={4}&honnhan={5}&muctieu=Tất cả&nuoc=Vietnam&btn_submit=",
                                                       page, param.GioiTinh, param.TuTuoi, param.DenTuoi, param.NoiO, hn.Id);
                    Log.WriteLog(_fileLog, $"Tìm {linkTimKiem}");
                    linkTimKiem = "https://henhoketban.vn/timnguoiyeuonline.php" + linkTimKiem;
                    var response = RequestToWeb.GET(new Uri(linkTimKiem), false);
                    #endregion

                    #region Lấy dữ liệu
                    string sKQTimKiem = RequestToWeb.ReadStream(response);
                    sKQTimKiem = HttpUtility.HtmlDecode(sKQTimKiem);

                    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                    document.LoadHtml(sKQTimKiem);

                    var results_search2 = document.DocumentNode.QuerySelectorAll("div#maincontent > table");
                    if (results_search2.Count() <= 7)
                    {
                        break;
                    }
                    foreach (var v in results_search2)
                    {
                        ThongTinTaiKhoan tk = new ThongTinTaiKhoan();

                        var hangThongTin = v.QuerySelectorAll("tr > td");
                        if (hangThongTin.Count() >= 3)
                        {
                            var ten_gioiTinh_tuoi_honNhan = hangThongTin.ElementAt(1).QuerySelectorAll("h3").ElementAt(0);
                            tk.TenHienThi       = ten_gioiTinh_tuoi_honNhan.QuerySelectorAll("font").ElementAt(0).InnerText;
                            tk.GioiTinh         = ten_gioiTinh_tuoi_honNhan.QuerySelectorAll("font").ElementAt(1).InnerText;
                            tk.TinhTrangHonNhan = ten_gioiTinh_tuoi_honNhan.QuerySelectorAll("font").ElementAt(2).InnerText;
                            string tuoi  = string.Join("", ten_gioiTinh_tuoi_honNhan.InnerText.Where(p => p >= '0' && p <= '9'));
                            int    iTuoi = 0;
                            int.TryParse(tuoi, out iTuoi);
                            tk.Tuoi = iTuoi;

                            var duongDan = hangThongTin.ElementAt(0).QuerySelector("a");
                            tk.Url = "https://henhoketban.vn/" + duongDan.GetAttributeValue("href", "");

                            tk.Id   = tk.Url.Split('=')[1];
                            tk.NoiO = hangThongTin.ElementAt(0).QuerySelectorAll("center > font").ElementAt(0).InnerText;

                            if (param.ThoiGianDangNhap.HasValue)
                            {
                                try
                                {
                                    var thongTinThoiGianDangNhap = v.QuerySelectorAll("tr > td > p > font").ElementAt(1).InnerHtml;
                                    var thoiGianDangNhap         = LayThoiGian(thongTinThoiGianDangNhap.Substring(0, thongTinThoiGianDangNhap.IndexOf("<")).TrimAll());
                                    if (!thoiGianDangNhap.HasValue || thoiGianDangNhap.Value > param.ThoiGianDangNhap)
                                    {
                                        tk = null;
                                    }
                                    Debug.WriteLine($"{thongTinThoiGianDangNhap.Substring(0, thongTinThoiGianDangNhap.IndexOf("<")).TrimAll()} = {thoiGianDangNhap}, {((!thoiGianDangNhap.HasValue || thoiGianDangNhap.Value > param.ThoiGianDangNhap) ? "loại" : "nhận")}");
                                }
                                catch
                                {
                                }
                            }
                            if (tk != null)
                            {
                                yield return(tk);
                            }
                        }
                        else
                        {
                        }
                        if (param.DungTimKiem)
                        {
                            break;
                        }
                    }
                    #endregion
                    if (param.DungTimKiem)
                    {
                        break;
                    }
                    page++;
                    Log.WriteLog(_fileLog, $"Chuyển page tìm kiếm");
                }
                Log.WriteLog(_fileLog, $"Hoàn tất tìm kiếm");
            }
        }