Selenium WebドライバーとC#を使用してWeb検索からデータを保存しようとしていますが、すべて正常に機能しますが、テキストを保存すると、一部の文字のエンコードが間違っているようです。コードのスニペットは次のとおりです。
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fileName, true))
for (int i = 1; i <= 10; i++)
{
String xpath = "/html/body/div[5]/div[2]/div/div[6]/div/div[3]/div/div[2]/div/ol/li[" + i + "]/div"; // google
String element = driver.FindElement(By.XPath(xpath)).Text;
element.Replace(",", " ");
element = '"' + " " + element + " " + '"'+",";
{
ファイルで見つかったいくつかの奇妙な文字は、次のようなものです。
… ... </p>
どんな助けでも大歓迎です:)
############以下の解像度以下を使用して、この問題の解決策を見つけました。
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fileName, true, UnicodeEncoding.UTF8))