解決方法就是:
1. 先到 http://htmlagilitypack.codeplex.com 下載 HtmlAgilityPack 原始碼。
依照下面方式點擊即可下載。
2. 下載完畢,解壓縮檔案到 \HtmlAgilityPack.1.4.0.Source\HtmlAgilityPack\HtmlWeb.cs 的 1466 行左右,有一段程式碼:
Encoding respenc = !string.IsNullOrEmpty(resp.ContentEncoding) ? Encoding.GetEncoding(resp.ContentEncoding) : null;
修改改成以下所示:
Encoding respenc; if ((resp.ContentEncoding != null) && (resp.ContentEncoding.Length > 0)) { respenc = System.Text.Encoding.GetEncoding(resp.ContentEncoding); } else if ((resp.CharacterSet != null) && (resp.CharacterSet.Length > 0)) //根據Content-Type中獲取的charset { if (string.Compare(resp.CharacterSet, "UTF-8", true, System.Globalization.CultureInfo.InvariantCulture) == 0) respenc = System.Text.Encoding.GetEncoding("UTF-8"); else if (string.Compare(resp.CharacterSet, "BIG5", true, System.Globalization.CultureInfo.InvariantCulture) == 0) respenc = System.Text.Encoding.GetEncoding("BIG5"); else if (string.Compare(resp.CharacterSet, "iso-8859-1", true, System.Globalization.CultureInfo.InvariantCulture) == 0) respenc = System.Text.Encoding.GetEncoding("UTF-8"); else respenc = System.Text.Encoding.GetEncoding(resp.CharacterSet); } else { respenc = System.Text.Encoding.GetEncoding("UTF-8"); }
再將整個專案重建,參考到 \HtmlAgilityPack.1.4.0.Source\HtmlAgilityPack\bin\Debug\HtmlAgilityPack.dll 來使用。
回目錄
回首頁
沒有留言 :
張貼留言