public List <ScrappedAdress> getScrappedAdresses(string siteAdress, string tagPath) { string[] splitedTags = splitTags(tagPath); HtmlWeb web = new HtmlWeb(); var htmlDoc = web.Load(siteAdress); StringBuilder sb = new StringBuilder(); List <ScrappedAdress> aList = new List <ScrappedAdress>(); HtmlNodeCollection node = htmlDoc.DocumentNode.SelectNodes("//" + splitedTags[splitedTags.Length - 3]); for (int i = 0; i < aList.Count; i++) { Console.WriteLine($"Country: {aList[i].Country} \nAdress: {aList[i].ConnectionAdress} \nPort: {aList[i].Port}\n"); } foreach (var tagNode in node.Descendants(splitedTags[splitedTags.Length - 2])) { ScrappedAdressBuilder sab = new ScrappedAdressBuilder(); foreach (var tag in tagNode.Descendants(splitedTags[splitedTags.Length - 1])) { if (tag.NodeType == HtmlNodeType.Element) { sab.FilterPart(tag); } } ScrappedAdress sa = (ScrappedAdress)sab.buildScrappedObject(); if (sa.Country != "" && sa.Country != null) { aList.Add(sa); } } FilesIO.serializeList("serList", aList); return(aList); }
public override ScrappedObject buildScrappedObject() { ScrappedAdress sa = new ScrappedAdress(); sa.setCountry(Country); sa.setPort(Port); sa.setConnectionAdress(ConnectionAdress); return(sa); }