2011-01-28 48 views
1

我想要做的是用戶將輸入一個URL到文本框中,就像在Facebook中我想要能夠檢索頁面中的圖像,meta關鍵字,元描述等。Facebook共享鏈接數據提取如何處理asp.net和c#?

基本上我想做與Asp.net和C#的Facebok Sahre鏈接屬性? 有什麼想法?

+0

檢查了這一點: http://stackoverflow.com/questions/7978186/how-to-extract-data-from-url-like-facebook-in-asp-net -mvc3 – 2011-12-06 10:54:52

回答

1

你必須新建一個WebClient()並執行http請求,然後解析出你想要的。

http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx

string html = string.Empty; 
using (WebClient client = new WebClient()) 
{ 
    client.Headers.Add("user-agent", 
     "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); 
    using (Stream data = client.OpenRead("http://someurl.com")) 
    using (StreamReader reader = new StreamReader(data)) 
    { 
     html = reader.ReadToEnd(); 
    } 
}