2
我想制作一个控制台应用程序,用于返回他们输入频道时的用户数量。我现在有它从Console.ReadLine()下载搜索页面作为html。这会返回一个成功的html页面,因为我添加了一个.Save来查看下载是否有任何输出。但是,当使用xcode刮取html时,它会返回null。我曾多次尝试使用Google Chrome副本xcode,但都没有运气。C#&HTML敏捷包 - 返回空
这里是我到目前为止的代码:
public static void GetYoutubeSubscriptions2()
{
string url = "https://www.youtube.com/results?search_query=" + Regex.Replace(Console.ReadLine(), @"\s+", "+");
Console.WriteLine(url);
HtmlWeb web = new HtmlWeb();
HtmlDocument document = web.Load(url);
//document.Save(path1);
var htmlNodes = document.DocumentNode.SelectNodes(@"//*[@id=""section - list - 231763""]/li[3]/div/div[2]/div[3]/span/span[1]");
foreach (var node in htmlNodes)
{
Console.WriteLine(node.InnerText);
}
Console.ReadLine();
}
任何帮助的建议表示赞赏! :)
感谢您的回答!对于使用此解决方案的其他人,请确保将HasClass放入静态类中! –