Asp.net mvc 使用mvc创建博客条目的快照/缩略图
我需要从博客的多个链接生成快照 我有一个这样的文本列表 “报告:Twitter将于本月通过@mashable发布音乐发现应用程序” 我想将链接显示为博客的快照,然后在我的视图中显示其文本。或者至少我需要把照片附在博客上 使用facebook debug,我得到了这个Asp.net mvc 使用mvc创建博客条目的快照/缩略图,asp.net-mvc,asp.net-mvc-4,html-parsing,Asp.net Mvc,Asp.net Mvc 4,Html Parsing,我需要从博客的多个链接生成快照 我有一个这样的文本列表 “报告:Twitter将于本月通过@mashable发布音乐发现应用程序” 我想将链接显示为博客的快照,然后在我的视图中显示其文本。或者至少我需要把照片附在博客上 使用facebook debug,我得到了这个 fb:app_id: 122071082108 og:url: http://mashable.com/2013/03/13/twitter-music-app/ og:type: article og:title: R
fb:app_id: 122071082108
og:url: http://mashable.com/2013/03/13/twitter-music-app/
og:type: article
og:title: Report: Twitter Will Release Music Discovery App This Month
og:image:
og:description: Twitter is planning to release a standalone music app for iOS called Twitter Music as soon as the end of this month, according to CNET. CNET reports that Twitter Music will help...
og:site_name: Mashable
og:updated_time: 1363267654
我从我的c#代码中尝试了相同的链接,访问了带有参数“q”的链接作为我想要的链接。我得到了与reply相同的html,但是我找不到相关的图片,因为不同链接的图片不同
有人能推荐一种更好的方法在mvc中实现这一点吗
访问facebook调试的控制器中的我的代码:
var client = new RestClient
{
BaseUrl = "http://developers.facebook.com/tools/debug/og/object"
};
var request = new RestRequest
{
DateFormat = DataFormat.Xml.ToString(),
Resource = "Add",
Method = Method.GET
};
request.AddParameter("q", "http://on.mash.to/10L1v49");
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
我从你的问题中了解到的是,你需要一个链接预览,就像我们在facebook共享区粘贴一些链接一样 FacebookDebug方法返回一个html页面,其中包含来自给定链接的博客条目的图像 使用HtmlAgilityPack解析从facebook调试返回的html
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);
HtmlNode root = doc.DocumentNode;
var imageurl = doc.DocumentNode.SelectNodes("//img/@src").LastOrDefault();
string imagesrc = imageurl.OuterHtml.ToString();
int start = imagesrc.IndexOf("url=");
int to = imagesrc.IndexOf("\"", start + "url=".Length);
string s = imagesrc.Substring(
start + "url=".Length,
to - start - "url=".Length);
string a = Uri.UnescapeDataString(s);
还有..这是你的博客图片。可以修改相同的函数,以取消博客条目的标题、描述和更新时间