|
3金钱
WebRequest webRequest = WebRequest.Create(url);
webRequest.Timeout = 1000 * 30;
webRequest.Headers.Set("Pragma", "no-cache");
WebResponse response = webRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("utf-8");
StreamReader streamReader = new StreamReader(responseStream, encoding);
string mg_encode = streamReader.ReadToEnd().ToString();
Match mc = Regex.Match(mg_encode, @"<title>([^<]*)</title>", RegexOptions.Multiline);
Match mc1 = Regex.Match(mg_encode, @"<TITLE>([^<]*)</TITLE>", RegexOptions.Multiline);
string href = mc.Groups[1].Value;
string href1 = mc1.Groups[1].Value;
功能是批量获取网站标题。用的ListView控件。
怎么能够同时获取utf8和gb2312的编码。 光使用utf-8有时候会出现乱码。
额。还有 Match mc = Regex.Match(mg_encode, @"<title>([^<]*)</title>", RegexOptions.Multiline);
Match mc1 = Regex.Match(mg_encode, @"<TITLE>([^<]*)</TITLE>", RegexOptions.Multiline);
怎么能简单点。。
|
最佳答案
查看完整内容
我的Httphelper类会自动识别编码,或者你去下载源码看看我是怎么处理的http://www.sufeinet.com/thread-3-1-1.html
|