R
R
Roman Kazarov2020-02-17 18:05:19
.NET
Roman Kazarov, 2020-02-17 18:05:19

Does anyone know a good material on parsers?

Suggest good material for learning AngleSharp or other modern C# parsing libraries.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-02-17
@vabka

css documentation regehi
selectors

D
Danila NV, 2020-02-21
@DanyaMo

AngeSharp is a good library but does not support XPath queries. IMHO, for parsing it is much more efficient to use XPath and, accordingly, the libraries that support it, such as HtmlAgilityPack or the built-in Selenium / Puppeteer tools.
Examples of XPath queries that are very difficult or impossible to write in CSS:
Find element A that contains the text "Login" or "Login":

//div[@class='header__login-head']/a[text()='Login' or text()='Войти']

Find a DIV element whose class attribute value contains the substring "line-header__filter-text" and the text "Tables" and return the parent of this element:
//div[contains(@class, 'line-header__filter-text') and text()='Планшеты']/../..

The ability to search within the text of element or attribute content and combine conditions with logical operators is very powerful. And this is only a small part. In AngleSharp, you would have to write a simpler CSS query, and then look up the DOM element in C# code using DOM tree navigation.
These queries will work in the same way (almost) in any library that supports XPath, as well as in Chrome Dev Tools in the search bar on the Elements tab (it's also convenient to debug there). There are also various plugins for debugging or building queries in Chrome or Firefox.
XPATH Tutorial

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question