问题
I have an .html file containing only text(formatted somehow).I am wondering if there is a way to copy all of the text(like if would do with ctrl+A) and assign it to a string So I can then export it to .txt file ? All this must happen from the code-behind(opening the html, selecting the text and assigning it to a string).
In the Microsoft.Office.Interop
I remember that there was an option for copying the active window selection or something, so I was wondering if this is possible and here.
回答1:
Use HttpAgilityPack. Someone could say it's overblown, but otherwise tomorrow you'll ask us how to convert the &code; that are in the file, and the next day you'll ask something else.
回答2:
use this for read from file
using (StreamReader sr = new StreamReader("TestFile.html"))
{
String line = sr.ReadToEnd();
Console.WriteLine(line);
}
http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
and this for read from url
WebClient client = new WebClient();
String htmlCode = client.DownloadString("http://test.com/file.html");
来源:https://stackoverflow.com/questions/18350208/how-to-copy-html-text-selection-and-assign-it-to-a-string-in-c-sharp