[ASP. NET] powerful web page processing class NSoup

Source: Internet
Author: User

If we encounter HTML processing in the project, if it is a. NET programmer, we strongly recommend using NSoup, otherwise it would be too painful to intercept the string. NSoup is an open-source framework and is a. NET porting version of JSoup. The usage is basically the same! NSoup click to download

Obtain the html code of the webpage. process the webpage html [csharp] view plaincopyprint?
  1. NSoup. Nodes. Document doc = NSoup. NSoupClient. Connect ("http://blog.csdn.net/dingxiaowie2013"). Get ();

    Or is the custom html used to generate the html page [csharp] view plaincopyprint?
    1. NSoup. Nodes. Document doc = NSoup. NSoupClient. Parse (HtmlString );


      But unfortunately NSoup is the default UTF-8, there will be garbled Chinese processing (for encoding is UTF-8 will naturally be normal, but some are GB2312 may be garbled)
      Solution to NSoup parsing HTML garbled characters

      1. Download the source code of the webpage and reprocess it.


      [Csharp] view plaincopyprint?
      1. // Download the webpage source code

      2. WebClient webClient = new WebClient ();

      3. String htmlString = Encoding. GetEncoding ("UTF-8"). GetString (webClient. DownloadData ("http://www.baidu.com "));

      4. NSoup. Nodes. Document doc = NSoup. NSoupClient. Parse (htmlString );


        2. Get the webpage stream



        [Csharp] view plaincopyprint?
        1. // Obtain the webpage stream

        2. WebRequest webRequest = WebRequest. Create ("http://blog.csdn.net/dingxiaowei2013 ");

        3. NSoup. Nodes. Document doc1 = NSoup. NSoupClient. Parse (webRequest. GetResponse (). GetResponseStream (), "UTF-8 ");




          The source code is the same as that of Baidu.


          ================================== Publisher Ding Xiaowei CSDN blog column ================ =====

          MyBlog: http://blog.csdn.net/dingxiaowei2013 MyQQ: 1213250243

          Unity QQ group: 375151422,858550, 6348968 cocos2dx QQ group: 280818155

          ==================================== Mutual learning, common progress ==============================





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.