public bool Login(string login, string password) { AvitoWebClient web = new AvitoWebClient(new CookieContainer()); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", "https://www.avito.ru/profile/login?next=%2Fprofile"); string data = "--bound\n" + "Content-Disposition: form-data; name=\"next\"\n" + "\n" + "/profile\n" + "--bound\n" + "Content-Disposition: form-data; name=\"login\"\n" + "\n" + "[email protected]\n" + "--bound\n" + "Content-Disposition: form-data; name=\"password\"\n" + "\n" + "kirillov4ever\n" + "--bound\n"; try { web.UploadString("https://www.avito.ru/profile/login", data); } catch (Exception e) { return(false); } creds = web.Container.GetCookies(new Uri("http://www.avito.ru")); return(true); }
public List <Region> GetRegions(bool reload = false) { if (!reload && regions != null) { return(regions); } regions = new List <Region>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(regionsUrl); } catch (Exception e) { regions = null; throw new LocationLoadException(); } JArray arr = JArray.Parse(json); foreach (JObject x in arr) { Region r = new Region(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); regions.Add(r); } return(regions.Count == 0 ? null : regions); }
public bool Login(string login, string password) { AvitoWebClient web = new AvitoWebClient(new CookieContainer()); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", "https://www.avito.ru/profile/login?next=%2Fprofile"); string data = "--bound\n" + "Content-Disposition: form-data; name=\"next\"\n" + "\n" + "/profile\n" + "--bound\n" + "Content-Disposition: form-data; name=\"login\"\n" + "\n" + "[email protected]\n" + "--bound\n" + "Content-Disposition: form-data; name=\"password\"\n" + "\n" + "kirillov4ever\n" + "--bound\n"; try { web.UploadString("https://www.avito.ru/profile/login", data); } catch(Exception e) { return false; } creds = web.Container.GetCookies(new Uri("http://www.avito.ru")); return true; }
public List <Advertisement> GetClosed() { List <Advertisement> list = new List <Advertisement>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(oldItemsUrl)); HtmlNodeCollection all = doc.DocumentNode.SelectNodes("//div[contains(@class,'item')]"); if (all != null) { foreach (HtmlNode node in all) { Advertisement ad = new Advertisement(); ad.Id = Int32.Parse(node.SelectSingleNode(".//input").GetAttributeValue("value", "0")); ad.Url = baseUrlSecure + node.SelectSingleNode(".//a[starts-with(@name,'item_')]").GetAttributeValue("href", ""); ad.Title = node.SelectSingleNode(".//a[starts-with(@name,'item_')]").InnerText; ad = Get(ad.Url); list.Add(ad); } } return(list); }
public UserLocation Default(bool reload = false) { if (!reload && def != null) { return(def); } def = new UserLocation(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch (Exception e) { def = null; throw new LocationLoadException(); } HtmlNode tmp; // City tmp = doc.DocumentNode.SelectSingleNode("//*[@id='region']/option[@selected]"); if (tmp != null) { def.City = new City { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // Metro tmp = doc.DocumentNode.SelectSingleNode("//*[@id='metro_id']/option[@selected]"); if (tmp != null) { def.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // District tmp = doc.DocumentNode.SelectSingleNode("//*[@id='district_id']/option[@selected]"); if (tmp != null) { def.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } return(def); }
public UserLocation Default(bool reload = false) { if (!reload && def != null) return def; def = new UserLocation(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch(Exception e) { def = null; throw new LocationLoadException(); } HtmlNode tmp; // City tmp = doc.DocumentNode.SelectSingleNode("//*[@id='region']/option[@selected]"); if (tmp != null) { def.City = new City { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // Metro tmp = doc.DocumentNode.SelectSingleNode("//*[@id='metro_id']/option[@selected]"); if (tmp != null) { def.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } // District tmp = doc.DocumentNode.SelectSingleNode("//*[@id='district_id']/option[@selected]"); if (tmp != null) { def.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "")), Name = tmp.NextSibling.InnerText }; } return def; }
public bool Delete(int id) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Referer", oldItemsUrl); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(oldItemsUrl, String.Format(deleteMask, id.ToString())); } catch (Exception e) { return false; } return true; }
public User GetDefault(bool reload = false) { if (!reload && def != null) { return(def); } def = new User(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch (Exception e) { def = null; throw new UserLoadException(); } string tmp; // Id def.Id = Int32.Parse(doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[2]/span").InnerText); // Name def.Name = doc.DocumentNode.SelectSingleNode("//*[@id='fld_name']").GetAttributeValue("value", ""); // Manager def.Manager = doc.DocumentNode.SelectSingleNode("//*[@id='fld_manager']").GetAttributeValue("value", ""); // Phone def.Phone = doc.DocumentNode.SelectSingleNode("//*[@id='fld_phone']").GetAttributeValue("value", ""); // Email tmp = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[1]/span").InnerText; tmp = tmp.Substring(0, tmp.IndexOf(' ')); def.Email = tmp; // Deny emails // TODO: get from local settings return(def); }
public bool Delete(int id) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Referer", oldItemsUrl); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(oldItemsUrl, String.Format(deleteMask, id.ToString())); } catch (Exception e) { return(false); } return(true); }
public User GetDefault(bool reload = false) { if (!reload && def != null) return def; def = new User(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); try { doc.LoadHtml(web.DownloadString(settingsUrl)); } catch(Exception e) { def = null; throw new UserLoadException(); } string tmp; // Id def.Id = Int32.Parse(doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[2]/span").InnerText); // Name def.Name = doc.DocumentNode.SelectSingleNode("//*[@id='fld_name']").GetAttributeValue("value", ""); // Manager def.Manager = doc.DocumentNode.SelectSingleNode("//*[@id='fld_manager']").GetAttributeValue("value", ""); // Phone def.Phone = doc.DocumentNode.SelectSingleNode("//*[@id='fld_phone']").GetAttributeValue("value", ""); // Email tmp = doc.DocumentNode.SelectSingleNode("//*[@id='profile']/div[1]/div[2]/div[3]/div[1]/div[1]/span").InnerText; tmp = tmp.Substring(0, tmp.IndexOf(' ')); def.Email = tmp; // Deny emails // TODO: get from local settings return def; }
private string PostImage(Image im) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", url1); List <byte> data = new List <byte>(); MemoryStream str = new MemoryStream(); im.Save(str, ImageFormat.Jpeg); StringBuilder s1 = new StringBuilder(); s1.AppendLine("--bound"); s1.AppendLine("Content-Disposition: form-data; name=\"image\"; filename=\"1.jpg\""); s1.AppendLine("Content-Type: image/jpeg"); s1.AppendLine(); StringBuilder s2 = new StringBuilder(); s2.AppendLine("\n--bound"); data.AddRange(Encoding.UTF8.GetBytes(s1.ToString())); data.AddRange(str.ToArray()); data.AddRange(Encoding.UTF8.GetBytes(s2.ToString())); string res = ""; try { byte[] arr = web.UploadData(imgUrl, data.ToArray()); res = Encoding.UTF8.GetString(arr); } catch (Exception e) { throw new WebException("Error making image posting\n"); } JObject jo = JObject.Parse(res); return(jo["id"].ToString()); }
public List <City> GetCities(int RegionId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(citiesUrl, RegionId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <City> cities = new List <City>(); foreach (JObject x in arr) { City c = new City(); c.Id = Int32.Parse(x["id"].ToString()); c.Name = x["name"].ToString(); cities.Add(c); } return(cities.Count == 0 ? null : cities); }
public List <Metro> GetMetros(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(metrosUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <Metro> metros = new List <Metro>(); foreach (JObject x in arr) { Metro m = new Metro(); m.Id = Int32.Parse(x["id"].ToString()); m.Name = x["name"].ToString(); metros.Add(m); } return(metros.Count == 0 ? null : metros); }
public List <District> GetDistricts(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(districtsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <District> districts = new List <District>(); foreach (JObject x in arr) { District d = new District(); d.Id = Int32.Parse(x["id"].ToString()); d.Name = x["name"].ToString(); districts.Add(d); } return(districts.Count == 0 ? null : districts); }
public List <Road> GetRoads(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(roadsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return(null); } List <Road> roads = new List <Road>(); foreach (JObject x in arr) { Road r = new Road(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); roads.Add(r); } return(roads.Count == 0 ? null : roads); }
public List<Advertisement> GetClosed() { List<Advertisement> list = new List<Advertisement>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(oldItemsUrl)); HtmlNodeCollection all = doc.DocumentNode.SelectNodes("//div[contains(@class,'item')]"); if (all != null) { foreach (HtmlNode node in all) { Advertisement ad = new Advertisement(); ad.Id = Int32.Parse(node.SelectSingleNode(".//input").GetAttributeValue("value", "0")); ad.Url = baseUrlSecure + node.SelectSingleNode(".//a[starts-with(@name,'item_')]").GetAttributeValue("href", ""); ad.Title = node.SelectSingleNode(".//a[starts-with(@name,'item_')]").InnerText; ad = Get(ad.Url); list.Add(ad); } } return list; }
public List<City> GetCities(int RegionId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(citiesUrl,RegionId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch(Exception e) { return null; } List<City> cities = new List<City>(); foreach (JObject x in arr) { City c = new City(); c.Id = Int32.Parse(x["id"].ToString()); c.Name = x["name"].ToString(); cities.Add(c); } return cities.Count == 0 ? null : cities; }
private string PostImage(Image im) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "multipart/form-data; boundary=bound"); web.Headers.Add("Referer", url1); List<byte> data = new List<byte>(); MemoryStream str = new MemoryStream(); im.Save(str, ImageFormat.Jpeg); StringBuilder s1 = new StringBuilder(); s1.AppendLine("--bound"); s1.AppendLine("Content-Disposition: form-data; name=\"image\"; filename=\"1.jpg\""); s1.AppendLine("Content-Type: image/jpeg"); s1.AppendLine(); StringBuilder s2 = new StringBuilder(); s2.AppendLine("\n--bound"); data.AddRange(Encoding.UTF8.GetBytes(s1.ToString())); data.AddRange(str.ToArray()); data.AddRange(Encoding.UTF8.GetBytes(s2.ToString())); string res = ""; try { byte[] arr = web.UploadData(imgUrl, data.ToArray()); res = Encoding.UTF8.GetString(arr); } catch (Exception e) { throw new WebException("Error making image posting\n"); } JObject jo = JObject.Parse(res); return jo["id"].ToString(); }
public List<Road> GetRoads(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(roadsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<Road> roads = new List<Road>(); foreach (JObject x in arr) { Road r = new Road(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); roads.Add(r); } return roads.Count == 0 ? null : roads; }
public List<Region> GetRegions(bool reload = false) { if (!reload && regions != null) return regions; regions = new List<Region>(); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(regionsUrl); } catch (Exception e) { regions = null; throw new LocationLoadException(); } JArray arr = JArray.Parse(json); foreach (JObject x in arr) { Region r = new Region(); r.Id = Int32.Parse(x["id"].ToString()); r.Name = x["name"].ToString(); regions.Add(r); } return regions.Count == 0 ? null : regions; }
public List<Metro> GetMetros(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(metrosUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<Metro> metros = new List<Metro>(); foreach (JObject x in arr) { Metro m = new Metro(); m.Id = Int32.Parse(x["id"].ToString()); m.Name = x["name"].ToString(); metros.Add(m); } return metros.Count == 0 ? null : metros; }
public List<District> GetDistricts(int CityId) { AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; string json = ""; try { json = web.DownloadString(String.Format(districtsUrl, CityId)); } catch (Exception e) { throw new LocationLoadException(); } JArray arr; try { arr = JArray.Parse(json); } catch (Exception e) { return null; } List<District> districts = new List<District>(); foreach (JObject x in arr) { District d = new District(); d.Id = Int32.Parse(x["id"].ToString()); d.Name = x["name"].ToString(); districts.Add(d); } return districts.Count == 0 ? null : districts; }
public Advertisement Get(string url) { string tmpurl = url; url = editUrl + url.Substring(url.IndexOf(".ru/") + 4).Replace('/', '_'); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(url)); HtmlNode node = doc.DocumentNode.SelectSingleNode("//form[@id='f_item']"); HtmlNode tmp; Advertisement ad = new Advertisement(); ad.User = new UserInfo.User(); ad.Location = new UserLocation(); ad.Parameters = new Dictionary<int, int>(); ad.Images = new List<Image>(); // Id ad.Id = Int32.Parse(url.Substring(url.LastIndexOf('_') + 1)); // URL ad.Url = tmpurl; // Title ad.Title = ""; // Body ad.Body = node.SelectSingleNode("//*[@name='description']").InnerText; // Name //ad.User.Name = "������� ����"; // Manager ad.User.Manager = node.SelectSingleNode("//*[@name='manager']").GetAttributeValue("value", ""); // Phone ad.User.Phone = node.SelectSingleNode("//*[@name='phone']").GetAttributeValue("value", ""); // Allow Mails ad.User.DenyEmails = node.SelectSingleNode("//*[@name='allow_mails']").GetAttributeValue("checked", "xxx") == "xxx"; // Email //ad.User.Email = "*****@*****.**"; // Location // Region ad.Location.Region = new Region { Id = Int32.Parse(node.SelectSingleNode("//*[@id='region']").GetAttributeValue("value", "0")) }; // City ad.Location.City = new City { Id = Int32.Parse(node.SelectSingleNode("//*[@name='location_id']").GetAttributeValue("value", "0")) }; // Metro tmp = node.SelectSingleNode("//*[@name='metro_id']//*[@selected]"); if (tmp != null) ad.Location.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // Road tmp = node.SelectSingleNode("//*[@name='road_id']//*[@selected]"); if (tmp != null) ad.Location.Road = new Road { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // District tmp = node.SelectSingleNode("//*[@name='district_id']//*[@selected]"); if (tmp != null) ad.Location.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) }; // End Location // Category ad.CategoryId = Int32.Parse(node.SelectSingleNode("//*[@name='category_id']").GetAttributeValue("value", "")); // Parameters HtmlNodeCollection par = node.SelectNodes("//*[contains(@name,'params')]"); foreach (HtmlNode x in par) { string id = x.GetAttributeValue("name", "").Substring(7); id = id.Substring(0, id.IndexOf(']')); int value = Int32.Parse(x.SelectSingleNode(".//*[@selected]").GetAttributeValue("value", "")); ad.Parameters.Add(Int32.Parse(id), value); } // Geo tmp = node.SelectSingleNode("//*[@name='coords[lat]']"); if (tmp != null) { ad.Coordinates = new GeoCoords { Latitude = tmp.GetAttributeValue("value", ""), Longitude = node.SelectSingleNode("//*[@name='coords[lng]']").GetAttributeValue("value", ""), Zoom = node.SelectSingleNode("//*[@name='coords[zoom]']").GetAttributeValue("value", "") }; } // Price ad.Price = Int32.Parse(node.SelectSingleNode("//*[@name='price']").GetAttributeValue("value", "")); // Images par = node.SelectSingleNode("//*[@name='images[]']").ParentNode.SelectNodes(".//img"); foreach (HtmlNode x in par) { string[] arr = x.GetAttributeValue("src", "").Split('/'); arr[3] = "640x480"; byte[] data; try { data = web.DownloadData(String.Join("/", arr)); } catch (Exception e) { return null; } MemoryStream ms = new MemoryStream(); ms.Write(data, 0, data.Length); Image im = Image.FromStream(ms); ad.Images.Add(im); } // End return ad; }
public Advertisement Get(string url) { string tmpurl = url; url = editUrl + url.Substring(url.IndexOf(".ru/") + 4).Replace('/', '_'); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Encoding = Encoding.UTF8; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(web.DownloadString(url)); HtmlNode node = doc.DocumentNode.SelectSingleNode("//form[@id='f_item']"); HtmlNode tmp; Advertisement ad = new Advertisement(); ad.User = new UserInfo.User(); ad.Location = new UserLocation(); ad.Parameters = new Dictionary <int, int>(); ad.Images = new List <Image>(); // Id ad.Id = Int32.Parse(url.Substring(url.LastIndexOf('_') + 1)); // URL ad.Url = tmpurl; // Title ad.Title = ""; // Body ad.Body = node.SelectSingleNode("//*[@name='description']").InnerText; // Name //ad.User.Name = "Частное лицо"; // Manager ad.User.Manager = node.SelectSingleNode("//*[@name='manager']").GetAttributeValue("value", ""); // Phone ad.User.Phone = node.SelectSingleNode("//*[@name='phone']").GetAttributeValue("value", ""); // Allow Mails ad.User.DenyEmails = node.SelectSingleNode("//*[@name='allow_mails']").GetAttributeValue("checked", "xxx") == "xxx"; // Email //ad.User.Email = "*****@*****.**"; // Location // Region ad.Location.Region = new Region { Id = Int32.Parse(node.SelectSingleNode("//*[@id='region']").GetAttributeValue("value", "0")) }; // City ad.Location.City = new City { Id = Int32.Parse(node.SelectSingleNode("//*[@name='location_id']").GetAttributeValue("value", "0")) }; // Metro tmp = node.SelectSingleNode("//*[@name='metro_id']//*[@selected]"); if (tmp != null) { ad.Location.Metro = new Metro { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // Road tmp = node.SelectSingleNode("//*[@name='road_id']//*[@selected]"); if (tmp != null) { ad.Location.Road = new Road { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // District tmp = node.SelectSingleNode("//*[@name='district_id']//*[@selected]"); if (tmp != null) { ad.Location.District = new District { Id = Int32.Parse(tmp.GetAttributeValue("value", "0")) } } ; // End Location // Category ad.CategoryId = Int32.Parse(node.SelectSingleNode("//*[@name='category_id']").GetAttributeValue("value", "")); // Parameters HtmlNodeCollection par = node.SelectNodes("//*[contains(@name,'params')]"); foreach (HtmlNode x in par) { string id = x.GetAttributeValue("name", "").Substring(7); id = id.Substring(0, id.IndexOf(']')); int value = Int32.Parse(x.SelectSingleNode(".//*[@selected]").GetAttributeValue("value", "")); ad.Parameters.Add(Int32.Parse(id), value); } // Geo tmp = node.SelectSingleNode("//*[@name='coords[lat]']"); if (tmp != null) { ad.Coordinates = new GeoCoords { Latitude = tmp.GetAttributeValue("value", ""), Longitude = node.SelectSingleNode("//*[@name='coords[lng]']").GetAttributeValue("value", ""), Zoom = node.SelectSingleNode("//*[@name='coords[zoom]']").GetAttributeValue("value", "") }; } // Price ad.Price = Int32.Parse(node.SelectSingleNode("//*[@name='price']").GetAttributeValue("value", "")); // Images par = node.SelectSingleNode("//*[@name='images[]']").ParentNode.SelectNodes(".//img"); foreach (HtmlNode x in par) { string[] arr = x.GetAttributeValue("src", "").Split('/'); arr[3] = "640x480"; byte[] data; try { data = web.DownloadData(String.Join("/", arr)); } catch (Exception e) { return(null); } MemoryStream ms = new MemoryStream(); ms.Write(data, 0, data.Length); Image im = Image.FromStream(ms); ad.Images.Add(im); } // End return(ad); }
public bool Post(Advertisement ad) { Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("seller_name", ad.User.Name); data.Add("manager", (ad.User.Manager == null) ? "" : ad.User.Manager); data.Add("phone", ad.User.Phone); data.Add("email", ad.User.Email); data.Add("allow_mails", (ad.User.DenyEmails) ? "1" : ""); data.Add("location_id", ad.Location.City.Id.ToString()); data.Add("metro_id", (ad.Location.Metro == null) ? "" : ad.Location.Metro.Id.ToString()); data.Add("district_id", (ad.Location.District == null) ? "" : ad.Location.District.Id.ToString()); data.Add("road_id", (ad.Location.Road == null) ? "" : ad.Location.Road.Id.ToString()); data.Add("category_id", ad.CategoryId.ToString()); foreach (KeyValuePair <int, int> x in ad.Parameters) { data.Add("params[" + x.Key.ToString() + "]", x.Value.ToString()); } data.Add("title", ad.Title); data.Add("description", ad.Body); if (ad.Coordinates != null) { data.Add("coords[lat]", ad.Coordinates.Latitude); data.Add("coords[lng]", ad.Coordinates.Longitude); data.Add("coords[zoom]", ad.Coordinates.Zoom); } data.Add("price", ad.Price.ToString()); data.Add("service_code", "free"); data.Add("main_form_submit", "Продолжить с пакетом «Обычная продажа»"); foreach (Image image in ad.Images) { data.Add("images[]", PostImage(image)); } AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); web.Headers.Add("Referer", url1); try { web.UploadString(url1, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("confirm")) { throw new WrongAdvertisementException(); } string date = ((int)((DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds)).ToString(); HttpWebRequest req = HttpWebRequest.Create(captchaUrl + date) as HttpWebRequest; req.Referer = url2; req.CookieContainer = auth.CredsCont; HttpWebResponse res; try { res = req.GetResponse() as HttpWebResponse; } catch (Exception ex) { return(false); } Image im = new Bitmap(res.GetResponseStream()); string cap; try { cap = captcha.GetCaptcha(im); } catch (Exception ex) { return(false); } data.Clear(); data.Add("captcha", cap); data.Add("service", "0"); data.Add("subscribe-position", "0"); web.Headers.Add("Referer", url2); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(url2, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("finish")) { throw new CaptchaException(); } return(true); }
public bool Post(Advertisement ad) { Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("seller_name", ad.User.Name); data.Add("manager", (ad.User.Manager == null) ? "" : ad.User.Manager); data.Add("phone", ad.User.Phone); data.Add("email", ad.User.Email); data.Add("allow_mails", (ad.User.DenyEmails) ? "1" : ""); data.Add("location_id", ad.Location.City.Id.ToString()); data.Add("metro_id", (ad.Location.Metro == null) ? "" : ad.Location.Metro.Id.ToString()); data.Add("district_id", (ad.Location.District == null) ? "" : ad.Location.District.Id.ToString()); data.Add("road_id", (ad.Location.Road == null) ? "" : ad.Location.Road.Id.ToString()); data.Add("category_id", ad.CategoryId.ToString()); foreach (KeyValuePair<int, int> x in ad.Parameters) { data.Add("params[" + x.Key.ToString() + "]", x.Value.ToString()); } data.Add("title", ad.Title); data.Add("description", ad.Body); if (ad.Coordinates != null) { data.Add("coords[lat]", ad.Coordinates.Latitude); data.Add("coords[lng]", ad.Coordinates.Longitude); data.Add("coords[zoom]", ad.Coordinates.Zoom); } data.Add("price", ad.Price.ToString()); data.Add("service_code", "free"); data.Add("main_form_submit", "���������� � ������� �������� �������"); foreach (Image image in ad.Images) data.Add("images[]", PostImage(image)); AvitoWebClient web = new AvitoWebClient(auth.CredsCont); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); web.Headers.Add("Referer", url1); try { web.UploadString(url1, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("confirm")) throw new WrongAdvertisementException(); string date = ((int)((DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds)).ToString(); HttpWebRequest req = HttpWebRequest.Create(captchaUrl + date) as HttpWebRequest; req.Referer = url2; req.CookieContainer = auth.CredsCont; HttpWebResponse res; try { res = req.GetResponse() as HttpWebResponse; } catch (Exception ex) { return false; } Image im = new Bitmap(res.GetResponseStream()); string cap; try { cap = captcha.GetCaptcha(im); } catch (Exception ex) { return false; } data.Clear(); data.Add("captcha", cap); data.Add("service", "0"); data.Add("subscribe-position", "0"); web.Headers.Add("Referer", url2); web.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); try { web.UploadString(url2, Stringify(data)); } catch (Exception ex) { throw new AvitoNetworkException(); } if (!web.ResponseUrl.Contains("finish")) throw new CaptchaException(); return true; }