网页源代码截取

wplwpl2008 2008-07-13 02:47:22
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
System.Net.HttpWebRequest req;
System.Net.HttpWebResponse res;
string url = "http://www.baidu.com";
req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
res = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.StreamReader strm = new System.IO.StreamReader(res.GetResponseStream(), Encoding.GetEncoding("gb2312"));
richTextBox1.Text = strm.ReadToEnd();

}
}
}

我现在得到了网页里的源代码,我想提取有用的。
如<title><</title>直接的。
这个如何写呀?
...全文
138 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wplwpl2008 2008-07-13
  • 打赏
  • 举报
回复
你有这方面的例子叫我参考下吗?
bindsang 2008-07-13
  • 打赏
  • 举报
回复
简单的用正则表达式;复杂一点的嘛,转XML吧,有个MS的SgmlReader类可以转,然后用xpath搞定吧(我做网页分析的时候最喜欢用的);要是遇到原HTML不完整或有错误转不成XML的话,只能用HTMLDocument了,这个好像只能是在WebBrower里面取到吧,有点重量级了,而且不能在命令行程序里用,不知道能不能把HTMLDocument单独搞出来用。
Sant11 2008-07-13
  • 打赏
  • 举报
回复
我倒是有,呵呵,不过我出差了,手头没有,^_^,别打人。
用c#webBrowser就可以提取内容。
我写过从网页上获取天气。存如数据库

110,024

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧