Fizzler and QuerySelectorAll

I found Fizzler as an html parser and jQuery as a selector. But it seems that visual studio cannot resolve the QuerySelectorAll method.

here is my code:

 using HtmlAgilityPack; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument document = web.Load(url); var c = document.QuerySelectorAll('div'); 

Did I miss any links?

EDIT: after some searching, I found this code to use Fizzler

 HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); const string search = "td"; SelectorGenerator<HtmlNode> selectorGenerator1 = new SelectorGenerator<HtmlNode>(new HtmlNodeOps()); HumanReadableSelectorGenerator selectorGenerator2 = new HumanReadableSelectorGenerator(); Parser.Parse(search, new SelectorGeneratorTee(selectorGenerator1, selectorGenerator2)); var c = selectorGenerator1.Selector(Enumerable.Repeat(doc.DocumentNode, 1)).ToList(); 

I am still looking to find a good answer for my question.

+4
source share
5 answers

Perhaps it:

 using Fizzler.Systems.HtmlAgilityPack; 

Also give a snapshot of CsQuery, my C # jQuery port: https://github.com/jamietre/CsQuery

 var dom = CQ.CreateFromUrl(url); var c = dom["div"]; 

.. plus everything you used for jQuery.

+4
source

Old question, but it works:

 using HtmlAgilityPack; using Fizzler.Systems.HtmlAgilityPack; var web = new HtmlWeb(); var document = web.Load("some-url"); var c = document.DocumentNode.QuerySelectorAll("div"); 

QuerySelectorAll is an extension method for the HtmlNode type, but you tried to use it on an HtmlDocument .

+2
source

Most likely you are missing a link to Fizzler.Systems.HtmlAgilityPack

I would recommend adding this nuget package. Fizzler

 using Fizzler.Systems.HtmlAgilityPack; using HtmlAgilityPack; using HtmlDoc = HtmlAgilityPack.HtmlDocument; 

and then you can use it as

 var html = new HtmlDoc(); html.LoadHtml(HtmlText); // Fizzler for HtmlAgilityPack is implemented as the // QuerySelectorAll extension method on HtmlNode var document = html.DocumentNode; // yields: [<p class="content">Fizzler</p>] document.QuerySelectorAll(".content"); 
+1
source

If you are using QuerySelectorAll, you must create an array to check if the div is invalid, and then you can use queryselector

  HtmlNode[] test= html.DocumentNode.QuerySelectorAll("div.hlogo").ToArray(); for (int rowcounter = 0; rowcounter < test.Count(); rowcounter++) { var logoname = test[rowcounter].QuerySelector("a").InnerText; } 
0
source

I had the same problem and it was resolved. Perhaps you made my mistake. I defined assemblies in several configuration files. When I removed everything and installed the packages back, it worked fine.

  • Remove Fizzler , Fizzler.Systems.HtmlAgilityPack in the nuget manager.
  • Remove all these DLLs from the bin and debug folder.
  • Delete all dependency assemblies that are about these dlls in appconfig and webconfig
  • Install the latest Fizzler and Fizzler.Systems.HtmlAgilityPack packages in the nuget management packs.

    After that, you can use QuerySelectorAll and other methods without errors where you want.

Do not install HtmlAgilityPack alone. When you install Fizzler, HtmlAgilityPack will be installed automatically.

0
source

Source: https://habr.com/ru/post/1415932/


All Articles