日期:2014-05-19  浏览次数:21114 次

100分求一"提取WEB数据入库" C#的例子
最好是正则表达式提取的,用XPATH也可以.接此机会好好学习学习正则表达式

------解决方案--------------------
能说得更详细些吗?

都需要提取哪些数据...
------解决方案--------------------
如果是提取网页数据...

try..

using System.Net;

private string GetHtmlContent(string uriStr)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriStr);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
string content = sr.ReadToEnd();
sr.Close();
response.Close();
return content;
}
catch (Exception ex)
{
//处理
}
}
------解决方案--------------------
提取链接信息..

//从网页中提取链接信息
private List <string> GetHyperLinks(string content)
{
try
{
MatchCollection mc = Regex.Matches(content, " <a[\\s\\S]*?href=(\ "(? <href> [^\ "]*)\ "| '(? <href> [^ ']*) '|(? <href> [^> \\s]*))[^> ]*?> ", RegexOptions.IgnoreCase | RegexOptions.Singleline);
List <string> list=new List <string> ();
foreach (Match m in mc)
{
list.Add(m.Groups[ "href "].Value);
}
return list;
}
catch (Exception ex)
{
//处理..
}
}
------解决方案--------------------
关注,多整些让俺也学习学习
------解决方案--------------------
QQ群:323373