Introduction to AngleSharp, an HTML tool, and anglesharp

Source: Internet
Author: User

Introduction to AngleSharp, an HTML tool, and anglesharp
Introduction to AngleSharp, an HTML Tool

AngleSharpIs A. NET (C #)-Based DLL component specially designed for parsing xHTML source code.

Project address: https://github.com/FlorianRappl/AngleSharp

I mainly introduce some usageAngleSharpI will take the http://www.cnblogs.com site as the prototype. Other similar components include:
China:Jumony
Github address: https://github.com/Ivony/Jumony
Author Blog address: http://www.cnblogs.com/Ivony/
Foreign countries:Html Agility Pack
Address: http://htmlagilitypack.codeplex.com/
For details, you can search for the differences and performance of the three items. Next we will discuss the main roleAngleSharp

  • Introduce AngleSharp to the project and use NuGet to execute commands (in fact, I am installing force .)Install-Package AngleSharp

  • Add reference Using AngleSharp to the Project

  • First, obtain the HTML source code of the CnBlogs homepage.

    static public string GetHtml(){    HttpWebRequest myReq =    (HttpWebRequest)WebRequest.Create("http://www.cnblogs.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();}
  • Obtain the title of all current blog posts on the Cnblogs Homepage

    Private static void Main (string [] args) {// find the title of all articles string cnblogsHtml = GetHtml ();

    // Load HTML var document = DocumentBuilder. html (cnblogsHtml); // you must use = here. You cannot use Equals var titleItemList = document. all. where (m => m. className = "titlelnk"); int iIndex = 1; foreach (var element in titleItemList) {Console. writeLine (iIndex + ":" + element. innerHtml); iIndex ++ ;}}

    The above code output content: 1: JNDI learning Summary (3) -- use Druid in Tomcat to configure the JNDI Data Source
    2: How does our front-end communicate with designers?
    3: MVC5 + EF6 full tutorial 6
    4: differences between throttle and debounce auxiliary functions in common Javascript Class Libraries
    5: Walking young alone
    6: last week's hot spot Review (11.10-11.16)
    7: Android animation-Tween animation
    8: python Implementation of Naive Bayes Algorithm
    9: MVC three-layer Cascade
    10: C # printing and Design of labels (Bar Code) (I)
    11: OpenCASCADE Make Primitives-Box
    12: Implement hbase secondary index based on solr
    13: (16) Exploring the problems caused by Offset compensation in WebGIS
    14: javascript games-life games
    15: Android animation-Frame Animation
    16: C # Socket study Note 1
    17: lua table sorting
    18: ZooKeeper Series 1: ZooKeeper Quick Start
    19: [plug-in Development] -- 9 editor code block coloring-highlighted!
    20: University of Washington Computer Vision Course Notes (1)

The official website provides detailed documents and examples. You can take a look. The biggest advantage of this plug-in: Support for outputJavascript,LinqSyntax,IDAndClassSelector and dynamically add nodes. It is a powerful tool for. NET development.

AngleSharp document: https://github.com/FlorianRappl/AngleSharp/wiki/Documentation
AngleSharp example (Demo): https://github.com/FlorianRappl/AngleSharp/wiki/Examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.