阅读html文档中的文字 [英] read the text in the html document

查看:93
本文介绍了阅读html文档中的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在线阅读html文件中的内容并将所有内容文本保存在.txt文档中。谁能告诉我如何从html文档中读取文本?

解决方案

如果你的意思是下载网页的来源......



 使用系统; 
使用 System.IO;
使用 System.Net;





和功能。 ..



  public   static   void  SaveSource( string  url, string  path)
{
WebClient client = new WebClient();
string source = client.DownloadString(url);
File.WriteAllText(path,source);
}





为了获得更快的获取网页源的结果,您可能需要查看HttpWebRequests。


I want to read the content in html file online and save all the content text in .txt document. Can anyone tell me how to read the text from html document?

解决方案

If you mean download the source of a webpage...

using System;
using System.IO;
using System.Net;



And the function...

public static void SaveSource(string url, string path)
{
    WebClient client = new WebClient();
    string source = client.DownloadString(url);
    File.WriteAllText(path, source);
}



For faster results of getting the source of a webpage, you may want to look into HttpWebRequests.


这篇关于阅读html文档中的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆