C# - htmlagilitypack没有从网页上提取任何数据 [英] C# - htmlagilitypack not pulling any data from webpage
问题描述
我正在尝试编写这个脚本,从csgo-stats.com中删除我的号码。我遵循许多其他教程并基于我的代码主要在这篇文章:使用HtmlAgilityPack解析HTML页面但是当我运行我的项目时它只返回一个空白屏幕,没有错误代码或任何东西。这是源代码:
使用 HtmlAgilityPack;
使用系统;
使用 System.Xml.XPath;
命名空间 csgo_stats
{
class 计划
{
静态 void Main( string [] args)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml( http://csgo-stats.com/76561198286338578/ );
XPathNavigator docNav = doc.CreateNavigator();
XPathNavigator kills = docNav.SelectSingleNode( // @ content / div [2] / div [1] /部分[5] / DIV / UL /利[1] /强跨度>);
Console.WriteLine(kills);
Console.ReadKey();
}
}
}
我尝试过:
/ html / body / div [3] / main / section [1] / div / ul [1] / li [1] / div / p
// p [@ class ='current'] [1]
/ html / body / div [3] / main / section [1] / div / ul [1] / li [1] / div / p [@ class ='current'] [1]
查看页面的来源:
< main id = content class = 网站内容 >
< div id = load class = loading-spinner data-request = 76561198286338578 > 正在加载< < span class =code-leadattribute> / div >
< / main >
有显然没有元素代表你在该元素下的分数,所以你的SelectSingleNode
查询不会返回任何内容。
网站正在使用Javascript加载您的分数并填充HTML。 HAP将不执行该脚本,因此不会填充文档。
您需要找到另一种方法来加载您的脚本分数。
I am trying to write this script that pulls my number kills from csgo-stats.com. I follow many other tutorials and based my code mostly on this post: Parsing HTML page with HtmlAgilityPack But when I run my project it just returns a blank screen, with no error codes or anything. Here's the source code:
using HtmlAgilityPack;
using System;
using System.Xml.XPath;
namespace csgo_stats
{
class Program
{
static void Main(string[] args)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("http://csgo-stats.com/76561198286338578/");
XPathNavigator docNav = doc.CreateNavigator();
XPathNavigator kills = docNav.SelectSingleNode("//@content/div[2]/div[1]/section[5]/div/ul/li[1]/strong");
Console.WriteLine(kills);
Console.ReadKey();
}
}
}
What I have tried:
/html/body/div[3]/main/section[1]/div/ul[1]/li[1]/div/p
//p[@class='current'][1]
/html/body/div[3]/main/section[1]/div/ul[1]/li[1]/div/p[@class='current'][1]
Look at the source of the page:
<main id="content" class="site-content"> <div id="load" class="loading-spinner" data-request="76561198286338578">Loading</div> </main>
There are clearly no elements representing your score under that element, so yourSelectSingleNode
query doesn't return anything.
The site is using Javascript to load your score and populate the HTML. HAP will not execute that script, so the document will not be populated.
You'll need to find an alternative way to load your score.
这篇关于C# - htmlagilitypack没有从网页上提取任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!