public NicoNicoCommunityContent GetCommunity() { try { var a = NicoNicoWrapperMain.Session.GetAsync(CommunityUrl).Result; var doc = new HtmlDocument(); doc.LoadHtml2(a); var community_main = doc.DocumentNode.SelectSingleNode("//div[@id='community_main']"); var profile = community_main.SelectSingleNode("child::div/div/div[@id='cbox_profile']"); var news = community_main.SelectNodes("//div[parent::div[@id='community_news']]"); var ret = new NicoNicoCommunityContent(); ret.CommunityUrl = CommunityUrl; ret.ThumbnailUrl = profile.SelectSingleNode("child::table/tr/td/p/img").Attributes["src"].Value; ret.OwnerUrl = community_main.SelectSingleNode("child::div/div/div/div[@class='r']/p/a").Attributes["href"].Value; ret.OwnerName = "<a href=\"" + ret.OwnerUrl + "\">" + community_main.SelectSingleNode("child::div/div/div/div[@class='r']/p/a/strong").InnerText + "</a>"; ret.CommunityTitle = community_main.SelectSingleNode("child::div/div/h1").InnerText; ret.OpeningDate = community_main.SelectSingleNode("child::div/div/div/div/p/strong").InnerText; //---お知らせ--- ret.CommunityNews = new List <NicoNicoCommunityNews>(); if (news != null) { foreach (var notify in news) { var b = new NicoNicoCommunityNews(); b.Title = notify.SelectSingleNode("child::h2").InnerText; b.Description = HyperLinkReplacer.Replace(notify.SelectSingleNode("child::div[@class='desc']").InnerHtml.Trim()); b.Date = notify.SelectSingleNode("child::div[@class='date']").InnerText.Trim(); ret.CommunityNews.Add(b); } } //------ ret.CommunityLevel = profile.SelectSingleNode("child::table/tr/td/table/tr[1]/td[2]/strong").InnerText; ret.CommunityStars = profile.SelectSingleNode("child::table/tr/td/table/tr[1]/td[2]/span").InnerText; ret.CommunityMember = profile.SelectSingleNode("child::table/tr/td/table/tr[2]/td[2]").InnerHtml.Trim(); //---登録タグ--- ret.CommunityTags = new List <string>(); var tags = profile.SelectNodes("child::table/tr/td/table/tr[4]/td[2]/a"); if (tags != null) { foreach (var tag in tags) { ret.CommunityTags.Add(tag.SelectSingleNode("child::strong").InnerText); } } //------ ret.CommunityProfile = HyperLinkReplacer.Replace(profile.SelectSingleNode("child::div[@id='community_description']/div/div/div").InnerHtml.Trim()); //---特権--- ret.Privilege = new List <string>(); var privileges = profile.SelectNodes("child::table/tr/td/table/tr[7]/td[2]/div[2]/p"); ret.Privilege.Add(profile.SelectSingleNode("child::table/tr/td/table/tr[7]/td[2]/div[1]/p").InnerText); if (privileges != null) { foreach (var privilege in privileges) { ret.Privilege.Add(privilege.InnerText); } } //------ ret.TotalVisitors = profile.SelectSingleNode("child::table/tr/td/table/tr[6]/td[2]/strong").InnerText; ret.Videos = profile.SelectSingleNode("child::table/tr/td/table/tr[9]/td[2]").InnerHtml.Trim(); return(ret); } catch (RequestTimeout) { return(null); } }
public NicoNicoCommunityContent GetCommunity() { try { var a = NicoNicoWrapperMain.Session.GetAsync(CommunityUrl).Result; var doc = new HtmlDocument(); doc.LoadHtml2(a); var node = doc.DocumentNode; var community_main = node.SelectSingleNode("//main"); var header = node.SelectSingleNode("//header[@class='area-communityHeader']"); var news = node.SelectNodes("//div[parent::div[@id='community_news']]"); var ret = new NicoNicoCommunityContent(); ret.CommunityUrl = CommunityUrl; ret.ThumbnailUrl = header.SelectSingleNode("div/div/div[@class='communityThumbnail']/a/img").Attributes["src"].Value; ret.OwnerUrl = node.SelectSingleNode("//table[@class='communityDetail']/tr[1]/td/a").Attributes["href"].Value; ret.OwnerName = "<a href=\"" + ret.OwnerUrl + "\">" + header.SelectSingleNode("//table[@class='communityDetail']/tr[1]/td/a").InnerText.Trim() + "</a>"; ret.CommunityTitle = header.SelectSingleNode("div/div/div[@class='communityData']/h2/a").InnerText.Trim(); ret.OpeningDate = header.SelectSingleNode("//table[@class='communityDetail']/tr[2]/td").InnerText; //---お知らせ--- ret.CommunityNews = new List<NicoNicoCommunityNews>(); if(news != null) { foreach(var notify in news) { var b = new NicoNicoCommunityNews(); b.Title = notify.SelectSingleNode("child::h2").InnerText; b.Description = HyperLinkReplacer.Replace(notify.SelectSingleNode("child::div[@class='desc']").InnerHtml.Trim()); b.Date = notify.SelectSingleNode("child::div[@class='date']").InnerText.Trim(); ret.CommunityNews.Add(b); } } //------ ret.CommunityLevel = node.SelectSingleNode("//dl[@class='communityScale']/dd[1]").InnerText; ret.CommunityMember = node.SelectSingleNode("//dl[@class='communityScale']/dd[2]").InnerHtml.Trim(); //---登録タグ--- ret.CommunityTags = new List<string>(); var tags = node.SelectNodes("//ul[@class='tagList']/li"); if(tags != null) { foreach(var tag in tags) { ret.CommunityTags.Add(tag.SelectSingleNode("a").InnerText); } } //------ ret.CommunityProfile = HyperLinkReplacer.Replace(node.SelectSingleNode("//span[@id='profile_text_content']").InnerHtml.Trim()); //---特権--- ret.Privilege = new List<string>(); var privileges = node.SelectNodes("//div[@id='comLivePrivileged_data']/div/p"); ret.Privilege.Add(node.SelectSingleNode("//div[@id='comLivePrivileged_data']/p").InnerText); if(privileges != null) { foreach(var privilege in privileges) { ret.Privilege.Add(privilege.InnerText); } } //------ return ret; } catch(RequestTimeout) { return null; } }