在 VB.net 的 webbrowser 控件中查找 iframe 内的链接
我想在 iframe 中找到一个 url webbrowser 控件。
1)我的网络浏览器控件打开一个网址 2)该网址内有一个 iframe 3)该 Iframe 有一个链接,我想使用 vb.net 以编程方式获取该链接
I want to find a url webbrowser control inside iframe.
1) my webbrowsercontrol opena url
2)that url has one iframe inside it
3) That Iframe has a link which I want to grab programmatically using vb.net
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
随时使用 webBrowser1.Url.ToString() 获取当前打开链接的 URL。
您可以使用webBrowser1.DocumentText获取打开url的html代码。一旦你有了 html 代码,就可以使用字符串操作来查找“iframe src”值。
这可能有点复杂,因为您可能不知道需要处理多少个 iframe。
At any point of time use webBrowser1.Url.ToString() to get the URL of the current open link.
You can get the html code of the open url by using webBrowser1.DocumentText. Once you have the html code use string manipulation to find the "iframe src" value.
This can be abit complicated as you migt not know how may iframes you need to handle.
根据 HtmlWindow.WindowFrameElement 属性
As well there are some limitations for the FRAME elements according to HtmlWindow.WindowFrameElement Property
实际上,您需要做的就是这样...
Msgbox Webbrowser1.document.frames(0),getelementbyid("linkTagId").href
这将显示链接的 href,不必在字符串操作上浪费时间。
当然,您也可以在 for 循环中使用 .length 属性来遍历框架和链接。
另外,由于您在 exe 中运行代码,因此有多种方法可以绕过跨框架安全问题,网上有示例,只需在 google 中搜索“绕过跨框架安全网络浏览器控制”(不带引号)即可。
如果您需要更多帮助,请告诉我,我可以告诉您如何做。请记住,只有当父域名和 iframe 域名不同时才需要绕过跨框架内容(虽然不是子域名,但它们可以不同,没有问题)。
让我知道伙计:)
Actually, all you need to do is this...
Msgbox Webbrowser1.document.frames(0),getelementbyid("linkTagId").href
This will show you the href of the link, don't bother wasting time with string manipulation.
Of course, you can loop through the frames and links as well using the .length properties in a for loop.
Also, there are ways to bypass the cross-frame security issues since you are running the code in an exe, there are examples online, just search for "bypass cross-frame security webbrowser control" in google without the quotes.
If you need more help with these let me know as I can tell you how. Remember the cross frame stuff only need bypassing if the parent domain name and iframe domain name are different (not subdomains though, they can be different no problems).
Let me know mate :)