public void EachSchool(AngleSharp.Dom.IElement school) { School singleSchool = new School(); var element = school.QuerySelectorAll("td[class='class_list_cell']"); var eleLength = element.Length; string tmpUrl = element[0].QuerySelector("a").GetAttribute("href"); //sprintf的な活用法 singleSchool.url = $"https://www.meikogijuku.jp{tmpUrl}"; singleSchool.name = element[0].TextContent; singleSchool.address = element[1].TextContent; string tmpTel = element[2].QuerySelector("a").GetAttribute("href"); singleSchool.tel = tmpTel.Replace("tel:", ""); string tmpStation = element[3].TextContent; singleSchool.station = tmpStation.Replace("最寄駅", ""); this.schoolList.Add(singleSchool); }
/// <summary> /// 图片评论的图片 /// </summary> /// <param name="Comment_Image_DOM"></param> /// <returns></returns> private string CommentImageHandle(AngleSharp.Dom.IElement Comment_Image_DOM) { var image_src = Comment_Image_DOM.QuerySelectorAll("img").FirstOrDefault().GetAttribute("src"); if (!string.IsNullOrEmpty(image_src)) { //替换地址为原图地址 image_src = image_src.Replace(@"/thumb180/", @"/bmiddle/"); } return(image_src); }
/// <summary> /// 处理下一页链接 /// </summary> /// <returns></returns> private async Task <string> NextLinkHandle(AngleSharp.Dom.IElement dom) { string link = ""; //这里可能会有多种分页形式,需要不同情况不同判断 //1.加载更多 var divs_dom = dom.QuerySelectorAll("*"); if (divs_dom.Any()) { foreach (var x in divs_dom) { if ("comment_loading".Equals(x.GetAttribute("node-type")) || "click_more_comment".Equals(x.GetAttribute("action-type")) || "click_more_child_comment_big".Equals(x.GetAttribute("action-type"))) { link = x.GetAttribute("action-data"); break; } } } return(await Task.FromResult(link)); }