从 iframe 中获取 html
我正在制作一个应用程序,我想从 iframe 中获取一些内容, 在iFrame中代码是这样的。
我想要为我的应用程序提供网站“example2.com”。 我使用 ASP.NET(C#)、HtmlAgilityPack... 如何做到这一点?
我转到 iframe 的“src”链接。但我又一无所获。我给你链接点击此处。 打开这个页面,我想解析给定的链接。 1. 如何在没有指南针的情况下找到真北: 2. 如何在没有指南针的情况下找到真北。
I am making an app in which I want to fetch some content from iframe,
In iFrame code is like this.
<div class="abc">
<a class="abc" href="example.com" data-ctorig="example2.com" > **** </a>
</div>
I want the website "example2.com" for my app.
I use ASP.NET(C#), HtmlAgilityPack....
How to do this?
I go to the "src" link of the iframe. But again I found nothing. I give you the link click here.
Open this page, I want to parse given links.
1. How to Find True North Without a Compass:
2. How to Find True North Without a Compass.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 HtmlAgilityPack 指向 IFrame URL,而不是托管页面。
澄清...
如果我理解正确的话,您可以使用 WebClient 和 HtmlAgilityPack 获取 IFrame 的 HTML。
首先,您需要使用 WebClient 来获取主机页面的 HTML。然后,您需要使用 HtmlAgilityPack 解析主机页 HTML 并提取 IFrame URL。接下来,您将需要使用另一个 WebClient 从 IFrame URL 获取 HTML,然后再次使用 HtmlAgilityPack 解析响应,这应该会为您提供所需的内容。
当然,你的问题很模糊,所以我不完全确定这就是你想要的。无论哪种方式,以下链接都会对您有所帮助。
HtmlAgilityPack 教程
<一href="https://stackoverflow.com/questions/599275/how-can-i-download-html-source-in-c-sharp">使用 WebClient 下载 HTML
Point HtmlAgilityPack to the IFrame URL, not the Hosting page.
Clarified...
If I understand you correctly, you can fetch the HTML of the IFrame using a WebClient and HtmlAgilityPack.
First you need to use a WebClient to fetch the HTML of the host page. You'll then want to use HtmlAgilityPack to parse the host page HTML and extract the IFrame URL. Next you'll want to use another WebClient to get the HTML from the IFrame URL, and again, use HtmlAgilityPack to parse the response, which should give you what you're after.
Of course, your question is very vague, so I'm not entirely sure this is what you're after. Either way, the following links should help you.
HtmlAgilityPack Tutorial
Download HTML Using WebClient
假设您正在讨论从客户端浏览器中提供和呈现的页面执行此操作,则需要使用 JavaScript 而不是 C# 来执行此操作。
iframe
在客户端浏览器上呈现,因此您的服务器端代码将无法访问它。Assuming you're talking about doing this from a page served and rendered in a client browser, you would need to do so in JavaScript, not C#. The
iframe
is rendered on the client browser and so your server side code would have no access to it.