public bool VisitTo(string addr) { bool result = true; HttpWebRequest clientVisit = CreateWebRequest(addr, Method.GET); clientVisit.CookieContainer.Add(Cookies); // add cookies to container WebResponse requestVisit = clientVisit.GetResponse(); using (Stream streamGetData = requestVisit.GetResponseStream()) { using (StreamReader reader = new StreamReader(streamGetData)) { CsQuery.CQ DOM = CsQuery.CQ.Create(reader); // parse html CsQuery.IDomObject profile = DOM.Find("div").Where(e => e.ClassName == "logininfo").FirstOrDefault(); // find profile block CsQuery.IDomElement profileName = profile?.ChildElements.Where(e => e.Attributes["title"] == "Просмотр профиля").FirstOrDefault(); // find name if (profileName != null) { Console.WriteLine($"User: { profileName.FirstChild }"); Console.WriteLine($"Visit: `{ DOM.Find("title").Text() }`"); // return title course } else { Console.WriteLine("ERROR LOGIN"); } } } requestVisit.Close(); return(result); }
private List <Bookmark> ImportFromHtml() { // Для парсинга html выбрана библиотека CsQuery, т.к. другие варианты немного не подходят. // AngleSharp требует более высокую версию .NET Framework, а HtmlAgilityPack содержит баги и больше не поддерживается. // https://habr.com/en/post/273807/#AngleSharp // https://ru.stackoverflow.com/questions/420354/%D0%9A%D0%B0%D0%BA-%D1%80%D0%B0%D1%81%D0%BF%D0%B0%D1%80%D1%81%D0%B8%D1%82%D1%8C-html-%D0%B2-net List <Bookmark> bookmarks = new List <Bookmark>(); CsQuery.CQ cq = CsQuery.CQ.Create(File.ReadAllText(FileName)); foreach (CsQuery.IDomObject obj in cq.Find("a")) { if (obj.HasAttribute("href")) { Bookmark b = new Bookmark(); b.URL = obj.GetAttribute("href"); // Не английский текст выводится в виде кодов символов. Нужно декодировать. b.Name = System.Net.WebUtility.HtmlDecode(obj.InnerText); bookmarks.Add(b); } } return(bookmarks); }
protected override string GetNumberText(CsQuery.CQ node) { var p = node.Find("p"); if (p.Any()) { node = p; } return(node.Single().InnerText); }
protected override String GetDescription(CsQuery.CQ descriptionNode) { var caption = descriptionNode.Find("h3").Single().InnerText.Trim(); if (caption == String.Empty) { caption = descriptionNode.Find("h3 span").Single().InnerText.Trim(); } caption = Common.WrapText(caption); var detailedDescription = descriptionNode.Find(".au-accordion__target"); if (detailedDescription.Any()) { return(String.Format("{0}{1}{2}", caption, Environment.NewLine, String.Join(Environment.NewLine, detailedDescription.Single().ChildNodes.Select(node => Common.ParseNode(node))))); } else { return(caption); } }
protected override String GetNumberText(CsQuery.CQ node) { var text = node.Single().InnerText.Trim(); if (text == String.Empty) { return(node.Find("p").Single().InnerText.Trim()); } else { return(text); } }
private String[] GetUrls(CsQuery.CQ node) { return(node.Find("img").Not(".pdd-inline-sign__icon").Not("p span img").Select(img => img.GetAttribute("src")).ToArray()); }
protected override string GetDescription(CsQuery.CQ descriptionNode) { var nodes = descriptionNode.Find(@"[style=""font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: black;""]"); return(String.Join(Environment.NewLine, nodes.Select(node => Common.ParseNode(node)))); }