文章内容

2017/7/30 17:20:44,作 者: 黄兵

C#网络爬虫 WebUtility使用 转义字符 urlCode

背景:
在C#写网络爬虫时候,有时候需要将html中的转义字符进行处理,还有网址中的中文处理

一、html转义字符处理

1.ASP.NET中的html解析
HttpUtility.HtmlDecode()方法
位于:system.web
 
2.网络爬虫转换回来:

WebUtility.HtmlDecode 方法 (String)

将已经为 HTTP 传输进行过 HTML 编码的字符串转换为已解码的字符串。

命名空间:   System.Net
程序集:  System(System.dll 中)
 

二、网址中文处理

     中文转化GBK编码

      System.Web.HttpUtility.UrlEncode("中国",Encoding.GetEncoding("GBK"))

   GBK编码转中文:

           System.Web.HttpUtility.UrlDecode("中国", System.Text.Encoding.GetEncoding("GB2312"))

参考API网址:
https://msdn.microsoft.com/zh-cn/library/1e55w41w(VS.80).aspx
分享到:

发表评论

评论列表