我所拥有的很简单,一个带有 webbrowser-controll 的表单。
该网络浏览器访问一个网站。这一切都有效。
但是当他在页面上时我不想做的是让他运行一些 javascript 代码(或 jQuery,如果可能的话)来获取<b></b>
网站上标签之间的所有文本。
我该怎么做?
编辑: 感谢Birk,代码现在看起来像这样:
HtmlElementCollection bigFontTags = webBrowser1.Document.GetElementById("Frame_A").Document.GetElementsByTagName("b");
string[] textPieces = new string[bigFontTags.Count];
for (int i = 0; i < bigFontTags.Count; i++) {
textPieces[i] = bigFontTags[i].InnerText;
}
//process text
string bigText = String.Join(" ", textPieces);
MessageBox.Show(bigText);
但这不起作用。那是因为我需要获取的元素在框架和框架集的深处......这是布局(简单):
<frameset rows="0,1000" border="0" frameborder="0">
<frame src="/mail/Login?domain=telfort.nl&style=default&plain=0" name="SContentFrame" id="SContentFrame" scrolling="Auto" noresize="">
<frameset rows="88,*" framespacing="0" frameborder="0" border="0" bordercolor="#FFFFFF">
<frameset cols="182,*" framespacing="0" frameborder="0" border="0" bordercolor="#FFFFFF" onunload="ExitLogout()" onload="LoadFrames('/mail/Navigation?sid=1FBE4F29181F18D9358ABC082C7DEE1B6C67481B&userid=marcmeesters%40telfort.nl&seq=+Q&auth=+A&style=default','/mail/MessageList?sid=1FBE4F29181F18D9358ABC082C7DEE1B6C67481B&userid=marcmeesters%40telfort.nl&seq=+Q&auth=+A&srcfolder=INBOX&chk=1&style=default')">
<frame src="/supp/blank.htm" name="Frame_A" id="Frame_A" frameborder="0" scrolling="Yes" marginwidth="0" marginheight="0" bordercolor="#FFFFFF" border="0">
<form name="phoenix" method="post" action="" onsubmit="return clickedButton">
And then are here some tables and the content that i want to get.....
那么我怎样才能从那里得到那个内容???(以一种很好的方式???)
EDIT2: 我将发布网站的生成源:(注意!我已经删除了所有不相关的内容......所以只有从开始到内容的方式)
<html><head>
<title>Telfort - Webmail</title>
<link rel="SHORTCUT ICON" href="http://www.telfort.nl/images/template/favicon.ico">
<link rel="stylesheet" href="/style/telfort/stylesheet.css" type="text/css" media="screen">
<!-- main.tpl 20001107 -->
<script type="text/javascript" src="/supp/phsec.js"></script>
<script type="text/javascript" src="/supp/client_sniffer.js"></script>
<script type="text/javascript" src="chrome-extension://bfbmjmiodbnnpllbbbfblcplfjjepjdn/js/injected.js"></script></head>
<frameset rows="0,1000" border="0" frameborder="0">
<frame src="/mail/Login?domain=telfort.nl&style=default&plain=0" name="SContentFrame" id="SContentFrame" scrolling="Auto" noresize="">
<html><head>
<title>Telfort - Webmail</title>
<link rel="SHORTCUT ICON" href="http://www.telfort.nl/images/template/favicon.ico">
<link rel="stylesheet" href="/style/telfort/stylesheet.css" type="text/css" media="screen">
<!-- main.tpl 20001107 -->
<script type="text/javascript" src="/supp/phsec.js"></script>
<script type="text/javascript" src="/supp/client_sniffer.js"></script>
</head>
<frameset rows="0,1000" border="0" frameborder="0">
<frame src="/mail/Login?domain=telfort.nl&style=default&plain=0" name="SContentFrame" id="SContentFrame" scrolling="Auto" noresize="">
<html><head>
<title>Telfort - Webmail</title>
<link rel="stylesheet" href="/style/telfort/stylesheet.css" type="text/css" media="screen">
<!-- main_frame.tpl 20060510 -->
<script src="/supp/phif.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function LoadFrames(t1,t2) {
NavWin(frames["Frame_NAV"],t1);
NavWin(frames["Frame_A"],t2);
}
function ExitLogout() {
window.open(NavURL("/mail/Logout?sid=5D3995C305E2F91F575EDF1E2F11F5D75A7DF6D8&userid=marcmeesters%40telfort.nl&seq=+Q&auth=+A&style=default&popup=1"),"Logout","resizable=yes,scrollbars=yes,status=0,width=10,height=10");
}
//-->
</script>
</head>
<frameset rows="88,*" framespacing="0" frameborder="0" border="0" bordercolor="#FFFFFF">
<frameset cols="182,*" framespacing="0" frameborder="0" border="0" bordercolor="#FFFFFF" onunload="ExitLogout()" onload="LoadFrames('/mail/Navigation?sid=5D3995C305E2F91F575EDF1E2F11F5D75A7DF6D8&userid=marcmeesters%40telfort.nl&seq=+Q&auth=+A&style=default','/mail/MessageList?sid=5D3995C305E2F91F575EDF1E2F11F5D75A7DF6D8&userid=marcmeesters%40telfort.nl&seq=+Q&auth=+A&srcfolder=INBOX&chk=1&style=default')">
<frame src="/supp/blank.htm" name="Frame_A" id="Frame_A" frameborder="0" scrolling="Yes" marginwidth="0" marginheight="0" bordercolor="#FFFFFF" border="0">
<html><head>
<title>Berichtenlijst</title>
<!-- folders_msglist.tpl 20001106 -->
<link rel="stylesheet" href="/style/telfort/stylesheet.css" type="text/css" media="screen">
</head>
<body marginwidth="0" marginheight="0">
<form name="phoenix" method="post" action="" onsubmit="return clickedButton">
AND HERE THE CONTENT!!!!
</form>
</frameset>
</frameset>
</frameset>
</frameset>
</html>
编辑3: 感谢Birk,问题解决了,这就是答案:
HtmlWindow SContentFrame = webBrowser1.Document.Window.Frames[1];
HtmlWindow Frame_A = SContentFrame.Document.Window.Frames[2];
HtmlElementCollection bigFontTags = Frame_A.Document.GetElementsByTagName("b");
string[] textPieces = new string[bigFontTags.Count];
for (int i = 0; i < bigFontTags.Count; i++) {
textPieces[i] = bigFontTags[i].InnerText;
}
string bigText = String.Join(" ", textPieces);
MessageBox.Show(bigText);