0
我正在使用WebClient
類中的DownloadString
從頁面中讀取內容,然後使用StreamWriter
類將其內容寫入靜態HTML文件。在我正在閱讀的頁面中,有一個內聯javascript方法,它只是設置一個錨元素的OnClick
屬性來設置我在查看靜態HTML頁面時發現的window.location = history.go(-1);
,有一個奇怪的字母顯示不是呈現在動態網頁上。DownloadString然後寫入頁面問題
WebClient的& SteamWriter代碼
using (var client = new WebClient())
{
var html = client.DownloadString(url);
//This constructor prepares a StreamWriter (UTF-8) to write to the specified file or will create it if it doesn't already exist
using (var stream = new StreamWriter(file, false, Encoding.UTF8))
{
stream.Write(html);
stream.Close();
}
}
動態網頁的HTML代碼段的問題
<span>Sorry, but something went wrong on our end. Click <a href="#" onclick="window.location.href = history.go(-1);">here</a> to go back to the previous page.</span>
靜態頁面的HTML代碼段
<span>Sorry, but something went wrong on our end. Â Click <a href="#" onclick="window.location.href = history.go(-1);">here</a> to go back to the previous page.</span>
我在想,加入Encoding.UTF8
參數可以解決這個問題,但它似乎沒有幫助。我需要做某種額外的編碼或解碼嗎?還是我完全錯過了這種類型的操作所需的其他東西?
或許這就是你看到的http://stackoverflow.com/questions/1461907/html-encoding-issues-%C3%82-character-showing-up-instead-of-nbsp –