Net Processing HTML page element tool class (htmlagilitypack. dll)

Source: Internet
Author: User
Introduction

This article introduces the tool class (htmlagilitypack) for net to process HTML page elements. DLL), the use of a lot of purposes should be such as collection functions, how to deal with the collected HTML string is a headache, it is too troublesome and error-prone to intercept. All the third-party DLL files in this article are used for processing.

 

Download

: Http://htmlagilitypack.codeplex.com/

Click "Download" to download the file.

 

Use

1. Add htmlagilitypack. dll reference (reference class using htmlagilitypack ;).

2. Obtain the value based on the input ID in HTML.CodeAs follows:

 //  Simulate user requests WebClient = New  WebClient (); WebClient. Encoding = System. Text. encoding. utf8;  String Htmlcontext = WebClient. downloadstring ( "  Http: // stone_w.cnblogs.com/  "  ); WebClient. Credentials = Credentialcache. defaultcredentials; //  Add authorization certificate WebClient. headers. Add ( "  User-Agent " , "  Microsoft Internet Explorer  "  ); WebClient. headers. Add (  "  Host  " , "  Www.cnblogs.com  "  );  //  Obtain HTML elements (htmlcontext is an HTML page string) Htmldocument htmldoc = New Htmldocument (); htmldoc. loadhtml (htmlcontext );  //  Load HTML pages Htmlnode navnode = htmldoc. getelementbyid ( "  ID  "  ); Response. Write (navnode. attributes [  "  Value  " ]. Value );

 

Summary

Htmlagilitypack can query value by ID and obtain a single element node, which is a built-in method of the htmldocument class. You can try to practiceExercise. Thank you ~

 

 

 

 

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.