取框架中的网页,里面的控件出来,并且操作

generhappy 2010-10-21 09:55:33
引用了mshtml,想在如下的代码基础上进行修改,请大大指正!!!

HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
object index = 1;
IHTMLWindow2 frame1 = (IHTMLWindow2)doc.frames.item(ref index);
HTMLDocument doc1 = (HTMLDocument)frame1.document;
IHTMLElement title_txt = (IHTMLElement)doc1.getElementById("kw");
//IHTMLElement body_txt = (IHTMLElement)doc1.getElementById("su");
IHTMLElement button_tj = (IHTMLElement)doc1.getElementById("su");
//if (title_txt == null || button_tj == null)
// return;
title_txt.setAttribute("value", this.textBox1.Text, 0);
//body_txt.setAttribute("value", this.richTextBox1.Text, 0);
button_tj.click();





...全文
152 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
generhappy 2010-10-21
  • 打赏
  • 举报
回复
一上午都没人啊,给自己顶一下。。。。
bingdian37 2010-10-21
  • 打赏
  • 举报
回复
以后遇到这样的问题,DHTML参考,这本书足够了。
另外有个好的调试开发环境,会加快你的探索速度。
比如firebug
wuyq11 2010-10-21
  • 打赏
  • 举报
回复
WebBrowser wb;
HTMLDocument doc = (HTMLDocument)wb.Document.DomDocument;
object index = 1;
IHTMLWindow2 frame1 = (IHTMLWindow2)doc.frames.item(ref index);
HTMLDocument doc1 = (HTMLDocument)frame1.document;

IHTMLElement title = (IHTMLElement)doc1.getElementById("");
骑猪看海 2010-10-21
  • 打赏
  • 举报
回复
那结贴了,害我看了一会,看到下面有答案了
generhappy 2010-10-21
  • 打赏
  • 举报
回复
自己给出答案吧。。。


string b = textBox3.Text;
HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;
object index = b;
IHTMLWindow2 frame1 = (IHTMLWindow2)doc.frames.item(ref index);
HTMLDocument doc1 = (HTMLDocument)frame1.document;

textBox4.Text = doc1.body.innerHTML;
generhappy 2010-10-21
  • 打赏
  • 举报
回复
我想提取某网页中某个框架的html代码,如下代码可以提取出网页的全部html代码,请问如何按照索引提取某个框架内的html代码呢

string url = textBox2.Text;
webBrowser1.Url = new System.Uri(url, System.UriKind.Absolute);
Uri uri = new System.Uri(url, System.UriKind.Absolute);
//Uri uri = new System.Uri(url, System.UriKind.Absolute);
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string html = sr.ReadToEnd();//此处是源码

sr.Close();
textBox4.Text = html;
sisi88 2010-10-21
  • 打赏
  • 举报
回复
能说下你要干什么吗?
xuan.ye 2010-10-21
  • 打赏
  • 举报
回复
如果是winfrom的话可以获取窗体的句柄进行操作

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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