Introduction of AngleSharp an DLL component for analyzing xHTML source code
- 2021-08-28 19:49:29
- OfStack
AngleSharp is an DLL component developed based on. NET (C #) specifically for parsing xHTML source code.
Project address: https://github.com/FlorianRappl/AngleSharp
I mainly introduce some of the use of AngleSharp commonly used methods, with you introduced, I will take this site site as a prototype. Other similar components are:
Domestic: Jumony
github Address: https://github.com/Ivony/Jumony
Abroad: Html Agility Pack
Project address: http://htmlagilitypack.codeplex.com/
Specific everyone can search and compare the differences and performance of the three. Next, let's mainly discuss that the protagonist is AngleSharp
Introducing AngleSharp into the project, using the NuGet tool to execute commands (actually I am pretending to force.) Install-Package AngleSharp
Adding references to Using AngleSharp in the project
First, we get the HTML source code of the CnBlogs home page
static public string GetHtml()
{
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("https://www.ofstack.com");
HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
return readStream.ReadToEnd();
}
Get the titles of all current blog posts on the homepage of jb51
private static void Main(string[] args) { // Find out all the article titles string cnblogsHtml = GetHtml();
// Loading HTML
var document = DocumentBuilder.Html(cnblogsHtml);
// You must use it here == Can't be used Equals
var titleItemList = document.All.Where(m => m.ClassName == "titlelnk");
int iIndex = 1;
foreach (var element in titleItemList)
{
Console.WriteLine(iIndex + ":" + element.InnerHtml);
iIndex++;
}
}
Output of the above code:
1:JNDI Learning summary (3) - Tomcat Use under Druid Configure JNDI Data source
2: How does our front end communicate with designers
3:MVC5+EF6 Getting Started with a Complete Tutorial 6
4: Discussion on Common Use Javascript Class library throttle And debounce Differences between auxiliary functions
5: Walk through youth alone
6: Last week's hot spot review ( 11.10-11.16 )
7:Android Animation - Complement space (Tween) Animation
8: Naive Bayesian algorithm python Realization
9:MVC3 Hierarchical mode
10:C# Label ( Bar code ) Printing and design based on (1)
11:OpenCASCADE Make Primitives-Box
12: Based on solr Realization hbase Adj. 2 Level index
13:(106)WebGIS Discussion on the problems caused by offset compensation in
14:javascript Games -- Life game
15:Android Animation - Frame animation
16:C# Socket Study notes 1
17:lua Table sorting
18:ZooKeeper Series No. 1 1 Articles: ZooKeeper Quick Start
19: "Plug-in development"- 9 Editor code block shading - Highlight!
20: University of Washington Computer Vision Course Notes ( 1 )
The official has provided detailed documents and examples, so you can go and see them. The biggest advantage of this plug-in is that it can output Javascript, Linq syntax, ID and Class selectors, and add nodes dynamically. It is a sharp weapon for the development of. NET.
AngleSharp Document: https://github.com/FlorianRappl/AngleSharp/wiki/Documentation
Example of AngleSharp (Demo): https://github.com/FlorianRappl/AngleSharp/wiki/Examples