开发者

Retrieving selected text from a webpage inside iframe using in asp.net c#?

I go开发者_如何学编程t a weird task to do. I need to load a webpage inside an iframe. And whatever text I select within the iframe, I need to retrieve that from outside the iframe. I m not allowed to use javascript. Is there any way to do that in asp.net c#?


I agree it's a weird task. I personally would avoid situations like this, however if this is what you have to do this is how I would approach it.

  1. I recommend you get a library called Html Agility Pack
  2. Add a reference to the HTMLAgilityPack.dll to your asp.net application.
  3. If you know the url to the page in the iframe, scrape that website, eg

    WebClient webClient = new WebClient();
    byte[] reqHTML;
    reqHTML = webClient.DownloadData("http://www.urltothesiteyouwant.com/path/");
    UTF8Encoding objUTF8 = new UTF8Encoding();
    string htmlOfSite = objUTF8.GetString(reqHTML);
    
  4. Have a look at the Html Agility pack site and Example page for more info on how to use the library.

This will allow you to grab the text you need from the external site and display it on your own. Always important to check the legalities behind doing this as well and if the information you are looking to get off this site is allowed to be reproduced on other sites etc.

HTH.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜