我正在尝试使用 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))