Hot to get a web pages's text overview and photo from a link-similar to facebook when posting a link
When you posting a link on facebook they retrieve an image from that link's page and an overview of that page's content. Any ideas on how to have this kind of functionality?
Thanks in ad开发者_StackOverflow中文版vance.
It's not something that can be answered momentarily, but I can point you in the right direction. You have to read the Html page and parse it for all image tags. There are different ways of doing this, but as an example:
WebClient webClient = new WebClient();
webClient.Encoding = Encoding.UTF8;
string pageHtml = webClient.DownloadString(your_link_url);
Then you can search the string for <img>
tags and read their src
attributes. Facebook (and more recently MySpace) uses more complicated logic and rules to determine which images to grab (e.g. only certain size limits), so you can do something similar.
Btw, Facebook and MySpace recommend to use metatagging of content in order to "tell" their "fetchers" which images exactly they should fetch when sharing. So you could parse the page for those first, and if they are not present, continue with other images:
<meta name="title" content="TITLE_GOES_HERE" />
<meta name="description" content="EXCERPT_GOES_HERE" />
<link rel="image_src" href="IMAGE_URL_GOES_HERE" />
http://developerwiki.myspace.com/index.php?title=How_to_Add_Post_To_MySpace_to_Your_Site
精彩评论