FizzlerEx / HtmlAgilityPack QuerySelectorAll不工作 [英] FizzlerEx/HtmlAgilityPack QuerySelectorAll not working
问题描述
我一直在试图建立FizzlerEx,在 http://fizzlerex.codeplex.com/。添加到我的项目引用后,我已经尝试运行我的代码全部是下面列出的网站 - 给出的示例代码。
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;使用HtmlAgilityPack
;
使用Fizzler.Systems.HtmlAgilityPack;
命名空间Fizzler_Test
{
类节目
{
静态无效的主要(字串[] args)
{
VAR网络=新HtmlWeb();
变种文件= web.Load(http://example.com/page.html);
VAR页= document.DocumentNode;
的foreach(在page.QuerySelectorAll VAR项目(div.item))
{
VAR标题= item.QuerySelector(H3:没有(.share)) .InnerText;
VAR日期= DateTime.Parse(item.QuerySelector(跨度:EQ(2)。)的InnerText);
Var描述= item.QuerySelector(跨度:有(二))。innerHTML的;
}
}
}
不过,这会产生生成错误,声称:
错误1'HtmlAgilityPack.HtmlNode'不包含定义'QuerySelectorAll',没有扩展方法'QuerySelectorAll 接受式的第一个参数HtmlAgilityPack.HtmlNode'可以找到(是否缺少using指令或程序集引用?)
这似乎是QuerySelectorAll实际上不是HtmlNode的一部分,但考虑到这是从网站上逐字官方示例代码,我期望的创造者了解他们的图书馆工作。我很茫然,以什么实际的问题可能是
一个相关的问题似乎已经在这里找到,但没有合适的答案被发现了:<一HREF =http://stackoverflow.com/questions/10879720/fizzler-and-queryselectorall> Fizzler和QuerySelectorAll
这似乎是QuerySelectorAll实际上不是HtmlNode 的一部分,但考虑到这是采取
从网站逐字官方的示例代码,我期望的创造者了解如何
他们的图书馆工作。我在一个无所适从的实际问题可以
为。
块引用>
您即将这部分是正确的。虽然你是不是第二部分正确的,因为HAP的作者不是FizzlerEx的作者。问题是在别处。
单单看错误,你得到你需要去解决这个问题的唯一线索。错误1 HtmlAgilityPack.HtmlNode'不包含'QuerySelectorAll',没有扩展方法的定义QuerySelectorAll接受型HtmlAgilityPack.HtmlNode'的第一个参数可以找到(是否缺少using指令或程序集引用?)
那么,我们怎么搞定;它告诉我们,没有一个名为
QuerySelectorAll
在命名空间中的类HtmlNode
方法HtmlAgilityPack
。如果我们看一看HAP的源代码,你可以很容易地确定该错误消息是确实是正确的,因为是在我们寻找的类名称的方法。
为HtmlAgilityPack.HtmlNode源代码 - 类
这是哪里的方法,我们想用,但找不到?
这是的此处,在
Fizzler.Systems.HtmlAgilityPack .HtmlNodeSelection
级。
尝试一些东西后,我得到的代码完美只是因为它是工作。这个问题在Fizzler和HAP源代码之间的参考扩展。
如果您下载Fizzler你HtmlAgilityPack在同一时间。当您添加在Visual Studio中引用(假设你使用),只能添加
- Fizzler.Systems.HtmlAgilityPack.dll
- HtmlAgilityPack.dll
清洁你的解决方案,并重建它,它应该工作!
I've been attempting to set up FizzlerEx, found at http://fizzlerex.codeplex.com/. After adding the references to my project, I've attempted to run the example code given on the website- the entirety of my code is listed below.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using HtmlAgilityPack; using Fizzler.Systems.HtmlAgilityPack; namespace Fizzler_Test { class Program { static void Main(string[] args) { var web = new HtmlWeb(); var document = web.Load("http://example.com/page.html"); var page = document.DocumentNode; foreach (var item in page.QuerySelectorAll("div.item")) { var title = item.QuerySelector("h3:not(.share)").InnerText; var date = DateTime.Parse(item.QuerySelector("span:eq(2)").InnerText); var description = item.QuerySelector("span:has(b)").InnerHtml; } } }
However, this yields build errors, claiming that:
Error 1 'HtmlAgilityPack.HtmlNode' does not contain a definition for 'QuerySelectorAll' and no extension method 'QuerySelectorAll' accepting a first argument of type 'HtmlAgilityPack.HtmlNode' could be found (are you missing a using directive or an assembly reference?)
It would seem that QuerySelectorAll is not actually a part of HtmlNode, but given that this is the official example code taken verbatim from the website, I'd expect the creators understand how their library works. I'm at a loss as to what the actual issue could be.
A related problem seems to have been found here, but no suitable answer was ever found: Fizzler and QuerySelectorAll
解决方案It would seem that QuerySelectorAll is not actually a part of HtmlNode, but given that this is the official example code taken verbatim from the website, I'd expect the creators understand how their library works. I'm at a loss as to what the actual issue could be.
You are correct about this part. Though you are not correct about the second part, since the author of HAP isn't the author of FizzlerEx. The problem is elsewhere. Simply by looking at the error, you get the only clue you need to go to solve this .
Error 1 'HtmlAgilityPack.HtmlNode' does not contain a definition for 'QuerySelectorAll' and no extension method 'QuerySelectorAll' accepting a first argument of type 'HtmlAgilityPack.HtmlNode' could be found (are you missing a using directive or an assembly reference?)
So, what do we get; it tells us that there is no method called
QuerySelectorAll
in the classHtmlNode
in the namespaceHtmlAgilityPack
. If we take a look at the source code of HAP, you can easily determine that the error message is indeed correct, since there is no method by that name in the class we are looking.Source code for HtmlAgilityPack.HtmlNode - class
Where is this method that we want to use, but cannot find?
It's here, In the
Fizzler.Systems.HtmlAgilityPack.HtmlNodeSelection
-class.After trying a few things, I get the code to work perfectly just as it is. The problem was the extensions in the reference between Fizzler and HAP source code.
If you download Fizzler you get HtmlAgilityPack at the same time. When you add the references in Visual Studio (assuming you use that), only add
- Fizzler.Systems.HtmlAgilityPack.dll
- HtmlAgilityPack.dll
Clean your solution and rebuild it and it should work!
这篇关于FizzlerEx / HtmlAgilityPack QuerySelectorAll不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!