fix some explore bugs

This commit is contained in:
2018-07-15 11:50:23 +02:00
parent 5d1f05f91d
commit bfc63bc55d
2 changed files with 10 additions and 11 deletions
+5 -5
View File
@@ -39,20 +39,20 @@ namespace PocketSharp
var document = new HtmlDocument();
document.LoadHtml(html);
HtmlNodeCollection nodes = document.DocumentNode.SelectNodesByClass("media_item", true);
IEnumerable<HtmlNode> nodes = document.DocumentNode.SelectNodesByClass("media_item");
if (nodes == null || nodes.Count == 0)
if (nodes == null || !nodes.Any())
{
return items;
}
for (int i = 0; i < nodes.Count; i++)
for (int i = 0; i < nodes.Count(); i++)
{
HtmlNode node = nodes[i];
HtmlNode node = nodes.ElementAt(i);
PocketItem item = new PocketItem();
item.ID = node.Id;
HtmlNode title = node.Descendants().FirstOrDefault(x => x.HasClass("title"))?.FirstChild;
HtmlNode title = node.SelectNodeByClass("title")?.FirstChild;
if (title == null)
{
+5 -6
View File
@@ -1,23 +1,22 @@
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PocketSharp
{
internal static class HtmlNodeExtensions
{
public static HtmlNodeCollection SelectNodesByClass(this HtmlNode node, string className, bool isRoot = false)
public static IEnumerable<HtmlNode> SelectNodesByClass(this HtmlNode node, string className)
{
string prefix = isRoot ? "//" : "";
return node.SelectNodes($"{prefix}*[contains(@class, '{className}')]");
return node.Descendants().Where(x => x.HasClass(className));
}
public static HtmlNode SelectNodeByClass(this HtmlNode node, string className, bool isRoot = false)
public static HtmlNode SelectNodeByClass(this HtmlNode node, string className)
{
string prefix = isRoot ? "//" : "";
return node.SelectSingleNode($"{prefix}*[contains(@class, '{className}')]");
return node.Descendants().FirstOrDefault(x => x.HasClass(className));
}
}
}