在 VB.net 的 webbrowser 控件中查找 iframe 内的链接

发布于 2025-01-05 08:14:23 字数 127 浏览 1 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

碍人泪离人颜 2025-01-12 08:14:23

随时使用 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.

音栖息无 2025-01-12 08:14:23

根据 HtmlWindow.WindowFrameElement 属性

如果以下情况,您将无法访问 FRAME 元素或 FRAME 的文档:
FRAME 与包含它的 FRAMESET 位于不同的区域。对于一个
完整说明,请参阅关于跨框架脚本和安全性

As well there are some limitations for the FRAME elements according to HtmlWindow.WindowFrameElement Property

You cannot access a FRAME elements or the FRAME's document if the
FRAME is in a different zone than the FRAMESET that contains it. For a
full explanation, see About Cross-Frame Scripting and Security.

浅忆 2025-01-12 08:14:23

实际上,您需要做的就是这样...

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文