获取网页的信息(转)
来源:互联网 发布:水电预算工作量软件 编辑:程序博客网 时间:2024/05/29 10:12
用WebRequest抓取当前页面后,用正则表达式提取
例如:
scracth.htm
<html>
<body>
<a href="http://www.csdn.net"> 程序员 </a>
<a hfef="http://www.sohu.com"> 搜狐 </a>
<a href="http://www.sina.com.cn"> 新浪 </a>
</body>
</html>
后台代码:
public static void Main()
{
WebRequest wr = WebRequest.Create("http://127.0.0.1/scratch.htm");
WebResponse rs = wr.GetResponse();
StreamReader sr = new StreamReader(rs.GetResponseStream());
string htm = sr.ReadToEnd();
Console.WriteLine(htm);
string pattern = @" <a href=(? <url> [^> ]*)> (? <description> [^> ]*) </a> ";
RegexOptions m_options = RegexOptions.IgnoreCase ¦ RegexOptions.Multiline ¦ RegexOptions.Singleline;
Regex regex = new Regex(pattern, m_options );
Match m = regex.Match(htm);
while (m.Success)
{
Console.WriteLine("url=" + m.Groups["url"] + " description=" + m.Groups ["description"]);
m = m.NextMatch();
}
RL();
}
例如:
scracth.htm
<html>
<body>
<a href="http://www.csdn.net"> 程序员 </a>
<a hfef="http://www.sohu.com"> 搜狐 </a>
<a href="http://www.sina.com.cn"> 新浪 </a>
</body>
</html>
后台代码:
public static void Main()
{
WebRequest wr = WebRequest.Create("http://127.0.0.1/scratch.htm");
WebResponse rs = wr.GetResponse();
StreamReader sr = new StreamReader(rs.GetResponseStream());
string htm = sr.ReadToEnd();
Console.WriteLine(htm);
string pattern = @" <a href=(? <url> [^> ]*)> (? <description> [^> ]*) </a> ";
RegexOptions m_options = RegexOptions.IgnoreCase ¦ RegexOptions.Multiline ¦ RegexOptions.Singleline;
Regex regex = new Regex(pattern, m_options );
Match m = regex.Match(htm);
while (m.Success)
{
Console.WriteLine("url=" + m.Groups["url"] + " description=" + m.Groups ["description"]);
m = m.NextMatch();
}
RL();
}
- 获取网页的信息(转)
- 网页图片信息的获取
- 根据网页的URL获取网页信息
- 【转】获取网页表单信息
- 获取一个网页的meta信息
- EmailSpider-----获取网页上邮件的信息
- Java获取网页信息的方法
- python获取网页amf的信息
- 筛选网页信息获取天气预报
- 获取屏幕分辨率及网页信息
- python urllib* 获取网页信息
- C#获取网页信息示例
- Jsoup解析网页获取信息
- 通过HttpURLConnection获取网页信息
- 网页爬虫获取课程信息
- 用以获取网页源码并转码的方式。(新闻标题信息采集)
- 获取网页上的屏幕信息和鼠标坐标
- 从网页中获取有用的信息 html2text
- arcscene构建出色的三维世界
- memset
- 使用无极限treeview
- JavaScript图形库
- 扩展 Visual Editor 的控件和属性
- 获取网页的信息(转)
- replaceNode 在文档树中替换对象
- linux 菜鸟磁盘分区方案推荐
- ajax简单创建代码
- Linux 的魅力:访问 Nokia N800 摄像机
- HTML 标签
- socket模型使归纳
- 使用 RESTful 界面和 Project Zero 管理 HTTP 服务器
- 用Spring快速开发jms应用(JBOSS服务器)