如何以编程方式复制网页的源代码



我正在使用夏普开发。我正在使用 C# 制作一个窗口表单应用程序。在此应用程序中,我使用的是Web浏览器控件。我希望当我打开网页时,我的网络浏览器应以编程方式将该网页的源代码复制到文本文件中。我使用以下代码来完成此任务

string MSDNpage1 = webBrowser1.Document.Body.InnerText;
cxz.My.MyProject.Computer.FileSystem.WriteAllText("F:\Assignment.txt", MSDNpage1, true);

但这给出了一个错误,因为

"

类型或命名空间名称"My"在命名空间 cxz 中不存在(您是否缺少程序集引用?( CS0234)"

My 关键字存在于 VB.Net 而不是 C# 中。下面是在 C# 中将文本写入文件的代码:

// Compose a string that consists of three lines.
string lines = "First line.rnSecond line.rnThird line.";
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
file.WriteLine(lines);
file.Close();

参考: 代码: 写入文本文件 Visual C#

最新更新