标签:
//读取某个网页的html信息
private string GetHtmlCode(string url)
{
string htmlCode;
HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Timeout = 30000;
webRequest.Method = "GET";
webRequest.UserAgent = "Mozilla/4.0";
webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
HttpWebResponse webResponse = (System.Net.HttpWebResponse)webRequest.GetResponse();
if (webResponse.ContentEncoding.ToLower() == "gzip")//如果使用了GZip则先解压
{
using (System.IO.Stream streamReceive = webResponse.GetResponseStream())
{
using (var zipStream =
new System.IO.Compression.GZipStream(streamReceive, System.IO.Compression.CompressionMode.Decompress))
{
using (StreamReader sr = new System.IO.StreamReader(zipStream, Encoding.Default))
{
htmlCode = sr.ReadToEnd();
}
}
}
}
else
{
using (System.IO.Stream streamReceive = webResponse.GetResponseStream())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(streamReceive, Encoding.Default))
{
htmlCode = sr.ReadToEnd();
}
}
}
return htmlCode;
}
//读取某个txt文本
var
file = File.Open(
"D:\\tx.txt"
, FileMode.Open);
List<
string
> txt =
new
List<
string
>();
using
(
var
stream =
new
StreamReader(file))
{
while
(!stream.EndOfStream)
{
txt.Add(stream.ReadLine());
}
}
var
array =
new
string
[10,10];
var
line = 0;
txt.ForEach(t => {
var
row = 0;
t.Split(
‘,‘
).ToList().ForEach(p => {
array.SetValue(p, line, row);
row++;
});
line++;
});
file.Close();
标签:
原文地址:http://www.cnblogs.com/sdya/p/4653716.html