dom - htmlagilitypack invalid cast exception when grabbing nodes with certain classes -


I want to capture the div objects from a HTML page that contains some class types I am:

  HtmlNode authorNode = (HtmlNode) doc.DocumentNode.Descendants ("div"). Where (d = & gt; d.Attributes.Contains ("class") & amp;;; d.Attributes ["class"]. Value.Split (''). Any (B = & gt; B E.L. ("bineline") and B. E.L. ("list-pipe"));   

And I get this exception

  System The unauthorized cost extension was unrestricted. HResult = -2147467262 Message = Unable to remove type object 'Type' whereEnumerableIterator`1 [HtmlAgilityPack HtmlNode] 'to type' HtmlAgilityPack.HtmlNode 'source = Project 1 StackTrace: Project 1. Scrapper C: \ User \ Jürber \ Document \ Visual Studio 2010 \ Project \ Project 1 \ Project 1 \ Scrapper CS: Project 1 on Line 233 in ProcciIarticle (String Yury). Scrapper ProcessNode (String Yuri), HtmlNode parentNode) C: \ Users \ jgarber \ Documents \ Visual Studio 2010 \ Projects \ Project1 \ Project1 \ Scraper.cs: Row 194 Project1.Scraper.ExecuteScraping () in C: \ Users \ jgarber \ Documents \ Visual Studio 2010 \ Projects \ Project1 \ Project1 \ Scraper.cs: Row 107 in Project 1. WebsprapingMain.Main () in C: \ Users \ jgarber \ Documents \ Visual Studio 2010 \ Projects \ Project1 \ Project1 \ WebscrapingMain.cs: On line 64 systems .AppDomain._nExecuteAssembly (Runtime assembly, string [] AGR). System on AppDomain.ExecuteAssembly (string assembly file, proof assembly security, string [] args) at Microsoft. Visual Studio Hosting Process.HostProR RUAsersSambands () on systems. threading. ThreadHalper ThreadStart_Context (Object State) System. Threading on Execution Contains System.Threading.ExecutionContext.Run (ExecutionContext Execution Context, Context Callback Callback, Object State) on the RuNian (Execution Contest Execution System.Threading.ExecutionContext.Run (ExecutionContext execution context, context callback callback, object state, Boolean protected) But ext, ContextClallback callback, Object state, Boolean protected sync syntax) in system. threading. ThreadHalper Thread Start () Inner Expption:   

What I need to do now to do this, it is to work. Calculates the code of HtmlNode ;

, not just one node (where you are using where, which matches all the items ). If you are interested only in the first item, use first or first and default or if you know to be only one item, then Simply use or SingleAora default instead of just where .

Such:

  HtmlNode authorNode = doc.DocumentNode.Descendants ("div"). Where (D => D. Features. Consistency ("Class") & amp; A Features ["Square"] Value Sample (''). Any (B = & gt; B. Eckels "Biline") & amp; amp; B. Eulles ("list-pipe")). FirstOver Default ();   

Or assign to a count of HtmlNode:

  IEnumerable & lt; HtmlNode & gt; authorNodes = doc.DocumentNode.Descendants ("div"). Where (D = & gt; Properties are included ("square") & amp; A characteristic ["class"] value. Sample (''). Any (B => Ecklace ("bline") and B. Eccles ("list-pipe"));    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -