会抓取HTML的来

TianMaiCheng 2011-04-08 10:34:51
我想用C#调用MSHtml这个组件来解析Html文件,高手能不能给写个例程呢????


就是要编写成类似TreeView的那种的要解析Dom文档树的
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ki1381 2011-04-12
  • 打赏
  • 举报
回复
以获取超链接为例

foreach (mshtml.HTMLAnchorElement el in 某个mshtml.IHTMLDocument2对象.links)
{
MessageBox.Show(el.href);
}

其中某个mshtml.IHTMLDocument2对象可以是
(mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument
MOTA 2011-04-12
  • 打赏
  • 举报
回复
另外。。LZ 高手也会被你的结贴率吓跑的
qiri07 2011-04-12
  • 打赏
  • 举报
回复
楼主要分析html里面 的什么
MOTA 2011-04-12
  • 打赏
  • 举报
回复
参考
HTTPWEBRESPONSE
HTTPWEBREQUEST

System.Net.HttpWebRequest httpReq;

System.Net.HttpWebResponse httpResp;



String strBuff="";

char[] cbuffer=new char[256];

int byteRead=0;



try{

System.Uri httpURL=new Uri(txtURL.Text);



httpReq=(HttpWebRequest)WebRequest.Create(httpURL);

httpResp=(HttpWebResponse)httpReq.GetResponse();



System.IO.Stream respStream=httpResp.GetResponseStream();

System.IO.StreamReader respStreamReader=new StreamReader(respStream,Encoding.UTF8);

byteRead=respStreamReader.Read(cbuffer,0,256);

while(byteRead!=0)

{

String strResp=new String(cbuffer,0,byteRead);

strBuff=strBuff+strResp;

byteRead=respStreamReader.Read(cbuffer,0,256);

}

respStream.Close();

}

...

try{

FileStream fileStream=new FileStream(filename,FileMode.OpenOrCreate,FileAccess.Write);

byte[] byteSave=Encoding.ASCII.GetBytes(txtHTML.Text.ToString());

fileStream.Write(byteSave,0,byteSave.Length());

fileStream.Close();

}

catch...
spacher 2011-04-12
  • 打赏
  • 举报
回复
webrequest抓取html,正则抓取数据就行了
sjz123426 2011-04-12
  • 打赏
  • 举报
回复
不明白难题在哪里。、
beargo 2011-04-12
  • 打赏
  • 举报
回复
这个不需要高手才能做的吧..看你要解析什么样的数据了..正则提取或者XML解析都已经可以整大部份东西出来了.
蔡袅 2011-04-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tianmaicheng 的回复:]
不行……这里根本就没有什么高手你知道的………………
[/Quote] LZ要有信心,高手很多。
TianMaiCheng 2011-04-11
  • 打赏
  • 举报
回复
不行……这里根本就没有什么高手你知道的………………

110,538

社区成员

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

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

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