fix some explore bugs
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user