---
title: "解决HtmlAgilityPack中文乱码"
author: "csstome"
date: "2011-10-27T15:59:00Z"
tags: []
slug: "htmlagilitypack"
draft: false
lastmod: "2011-10-28T08:46:15Z"
id: 1219444
url: "https://csstome.iteye.com/blog/1219444"
---

[Html Agility Pack](http://htmlagilitypack.codeplex.com/)是用C#写的开源Html Parser。

在抓取163首页([http://www.163.com](http://www.163.com))代码如下：

不过有点问题是抓取的Code乱码了。

通过跟踪代码发现通过修改HtmlWeb.cs 中的第1466行（1.4.0.0版） 文件可以解决这个问题。

方法名为：

```
privateHttpStatusCodeGet(Uriuri,stringmethod,stringpath,HtmlDocumentdoc,IWebProxyproxy, ICredentialscreds)
```

原始实现源代码：

修改后的代码：

重新编译一下，就不会中文乱码了...