本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.GetElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.GetElementsByTagName方法的具体用法?C# HtmlDocument.GetElementsByTagName怎么用?C# HtmlDocument.GetElementsByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.GetElementsByTagName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadCatchUpDays
/// <summary>
/// Load the days for catch up
/// </summary>
/// <param name="parentCategory"></param>
/// <returns></returns>
public static List<Category> LoadCatchUpDays(Category parentCategory)
{
var doc = new HtmlDocument();
var results = new List<Category>();
var webRequest = (HttpWebRequest)WebRequest.Create(Properties.Resources._4OD_CatchUpUrl);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK)
throw new OnlineVideosException("Unable to retrieve response for 4OD Catch Up Category from " + Properties.Resources._4OD_CatchUpUrl + ", received " + webResponse.StatusCode.ToString());
doc.Load(webResponse.GetResponseStream());
// Load all the days from the page
foreach(HtmlNode node in doc.GetElementsByTagName("a").Where(x=>x.GetAttribute("href").StartsWith("/programmes/4od/catchup/date/")))
{
var result = new ExtendedCategory();
var dateParts = node.GetAttribute("href").Replace("/programmes/4od/catchup/date/", "").Split('/');
var videoDate = new DateTime(Convert.ToInt32(dateParts[0]), Convert.ToInt32(dateParts[1]), Convert.ToInt32(dateParts[2]));
result.Name = parentCategory.Name + " - " + videoDate.ToString("dd MMMM yyyy");
result.SortValue = videoDate.ToString("yyyyMMdd");
result.Other = "U~" + parentCategory.CategoryId() + "~" + Properties.Resources._4OD_RootUrl + node.GetAttribute("href");
result.Thumb = parentCategory.Thumb;
result.HasSubCategories = false;
result.ParentCategory = parentCategory;
results.Add(result);
}
return results;
}
示例2: LoadCatchUpVideos
/// <summary>
/// Load videos for the specified catch up category (day/channel)
/// </summary>
/// <param name="parentCategory"></param>
/// <returns></returns>
public static List<VideoInfo> LoadCatchUpVideos(Category parentCategory)
{
var doc = new HtmlDocument();
var results = new List<VideoInfo>();
var webRequest = (HttpWebRequest)WebRequest.Create(parentCategory.CategoryInformationPage());
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK)
throw new OnlineVideosException("Unable to retrieve response for 4OD Catch Up Video from " + parentCategory.CategoryInformationPage() + ", received " + webResponse.StatusCode.ToString());
doc.Load(webResponse.GetResponseStream());
var node = doc.GetElementsByTagName("span").Where(x => x.GetAttribute("class").Contains("tx-" + parentCategory.CategoryId())).FirstOrDefault();
if (node != null)
{
foreach (HtmlNode listItem in node.ParentNode.ParentNode.SelectSingleNode("ul").SelectNodes("li"))
{
var item = new VideoInfo();
item.Title = listItem.GetNodeByClass("title").InnerText + (listItem.GetNodeByClass("series-info") == null ? string.Empty : " - " + listItem.GetNodeByClass("series-info").InnerText);
item.Description = listItem.GetNodeByClass("synopsis").InnerText;
item.Airdate = listItem.GetNodeByClass("txtime").InnerText;
//item.ImageUrl = Properties.Resources._4OD_RootUrl + listItem.SelectSingleNode("a/img").GetAttribute("src");
item.Thumb = listItem.SelectSingleNode("a/img").GetAttribute("src");
item.Other = MakeWebSafe(listItem.GetNodeByClass("title").InnerText) + "~" + listItem.SelectSingleNode("a").GetAttribute("href").Split('#')[1];
results.Add(item);
}
}
return results;
}
示例3: LoadGeneralCategory
/// <summary>
/// Load general categories from the 4OD api page
/// </summary>
/// <param name="parentCategory"></param>
/// <returns></returns>
private List<Category> LoadGeneralCategory(string url, Category parentCategory)
{
var doc = new HtmlDocument();
var results = new List<Category>();
var webRequest = (HttpWebRequest)WebRequest.Create(url);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK)
throw new OnlineVideosException("Unable to retrieve response for 4OD from " + url + ", received " + webResponse.StatusCode.ToString());
doc.Load(webResponse.GetResponseStream());
// Load all the list items from the page into categories
results.AddRange(doc.GetElementsByTagName("li").Where(x => !string.IsNullOrEmpty(x.GetAttribute("class"))).Select(x => x.LoadGeneralCategoryFromListItem(parentCategory)));
// See if there's a next page of results to load
var nextPage = doc.GetElementsByTagName("ol").First().GetAttribute("data-nexturl");
if (nextPage != "endofresults")
results.AddRange(LoadGeneralCategory(Properties.Resources._4OD_RootUrl + nextPage, parentCategory));
return results;
}