System.Net.WebClient
获取数据,再用正则分析数据,获取指定内容
获取数据,再用正则分析数据,获取指定内容
解决方案 »
- 求助。我这样画多个多边形逼近圆为什么只有一条直线?
- 正在写一个软件自动更新的程序,求高手帮忙解决一个难题
- 高手进 这样的正则怎么写?
- 我用存储过程实现批量删除,可是在删除时遇到点小麻烦,请大家都进来看看
- C#调用webservice接口的问题,谢谢了
- 高手请进来指点~~~~~~~~~急~~~~~~~
- datagrid中的数据修改并保存后,发现当前正编辑的单元格并没有保存
- 两表间数据处理
- asp.net开发的网站地址如何变成每个产品的名称做地址呢?
- 急!vs2010简单的winapp,拖一个groupbox,报内存只读错误
- 大家说说,你们在。NET中实现GIF动画,是用什么做的?
- panel 滚动 问题!!!
private string GetHtmlSource(string url)
{
string html = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("GB2312"));
html = reader.ReadToEnd();
}
catch
{
MessageBox.Show("无法连接到远程服务器,请检查您的网络是否正常!", "提示");
}
return html; }
#endregion
http://www.cnblogs.com/skyiv/archive/2005/10/01/GetIP.html这里有“获取网页的HTML内容”的代码。
http://www.whitepages.com/5116/search/FindPerson?firstname=&name=wa&name_begins_with=1&city_zip=+01002&state_id=All+US&x=53&y=16
//string src = GetHtmlSource("http://www.whitepages.com/5116/search/Replay?search_id=40051390946113532971");
string src = GetHtmlSource("http://www.whitepages.com/5116/search/FindPerson?firstname=&name=wa&name_begins_with=1&city_zip=+01002&state_id=All+US&x=53&y=16");
MatchCollection mc = Regex.Matches(src, @"<div\s+class=""description"">\s*<h2><a[^>]*>(?<name>[\s\S]*?)</a>\s*</h2>\s*<p>(?<adress>[\s\S]*?)</p>\s*<p>(?<code>[\s\S]*?)</p>\s*<p[^>]*>(?<phone>[\s\S]*?)</p>", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["name"].Value + "\n";
richTextBox2.Text += m.Groups["adress"].Value + "\n";
richTextBox2.Text += m.Groups["code"].Value + "\n";
richTextBox2.Text += m.Groups["phone"].Value + "\n\n";
}private string GetHtmlSource(string url)
{
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24";
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, System.Text.Encoding.UTF8);
string htmlSource = (sr.ReadToEnd());
resStream.Close();
sr.Close();
return htmlSource;
}