UTF-8形式でウェブサイトのタイトルを取得する方法?

maliyassi:

私は、ウェブサイトのタイトルを取得したいです。私が使用しているclient.Encodingを、それはほぼ完璧だが、何かが間違っがあります。

それは私返し「|スカイスキャナーニュースブダペストの&#039観光」が、タイトルではなく、ユニコードのアポストロフィを持っています。

トルコ語の文字「S」はOKです。

string baslikCek()
        {
            Uri url = new Uri("https://www.skyscanner.com.tr/haberler/budapestede-gezilecek-yerler");
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            string html = client.DownloadString(url);
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            String title = (from x in doc.DocumentNode.Descendants()
                            where x.Name.ToLower() == "title"
                            select x.InnerText).FirstOrDefault().ToString();
            return title;
        }
rfmodulator:

ここに示したあなたの例は、間違っている&#039、末尾が不足しています;

あなたがこれを行うことができますので、しかし、それは、サーバーからの正しいです。

return System.Net.WebUtility.HtmlDecode(title);

これは同じではないEncoding.UTF8文字列データのバイナリ符号化です。

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=376973&siteId=1