0
A
回答
2
您可以使用HTML Agility Pack找到<img>
標籤。
1
您需要使用System.Net中的WebRequest類下載頁面的html。
然後,您可以解析HTML(使用HTML Agility Pack),然後使用WebRequest類提取圖像的URL並下載圖像。
下面是一些示例代碼,您開始:
static public byte[] GetBytesFromUrl(string url)
{
byte[] b;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
WebResponse myResp = myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
using (BinaryReader br = new BinaryReader(stream))
{
b = br.ReadBytes(100000000);
br.Close();
}
myResp.Close();
return b;
}
您可以使用此代碼下載原始字節爲某個網址(無論是網頁或圖像本身)。
0
/// Returns the content of a given web adress as string.
/// </summary>
/// <param name="Url">URL of the webpage</param>
/// <returns>Website content</returns>
public string DownloadWebPage(string Url)
{
// Open a connection
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(Url);
// You can also specify additional header values like
// the user agent or the referer:
WebRequestObject.UserAgent = ".NET Framework/2.0";
WebRequestObject.Referer = "http://www.example.com/";
// Request response:
WebResponse Response = WebRequestObject.GetResponse();
// Open data stream:
Stream WebStream = Response.GetResponseStream();
// Create reader object:
StreamReader Reader = new StreamReader(WebStream);
// Read the entire stream content:
string PageContent = Reader.ReadToEnd();
// Cleanup
Reader.Close();
WebStream.Close();
Response.Close();
return PageContent;
}
相關問題
- 1. ios將網站鏈接到應用程序播放歌曲
- 2. Django網站 - 使按鈕鏈接到不同的應用程序
- 3. 使用Facebook應用程序鏈接,我如何將用戶從我的網站鏈接到我的移動應用程序?
- 4. 將我的Java Web應用程序鏈接到網絡上?
- 5. iPhone應用程序從我們的網站鏈接圖像
- 6. 從我的網站/ Facebook應用程序點擊鏈接統計
- 7. 如何讓Facebook鏈接到我的網站而不是我的應用程序?
- 8. 如何在App Store應用程序中直接鏈接到我的應用程序評級網站?
- 9. 將谷歌鏈接到我的網站
- 10. 如何鏈接到我在亞馬遜安卓網站上的應用程序
- 11. 將網站上的聊天應用程序鏈接/同步到android
- 12. 將企業iPhone應用程序的省份鏈接到網站,以便公司員工可以從此網站鏈接下載應用程序?
- 13. 從我的應用程序鏈接到網頁
- 14. 如何將移動網站鏈接到我的PC版網站
- 15. WordPress網站已將我的鏈接重定向到onclickads網站
- 16. 將pdf鏈接到Windows應用程序中的菜單項C#
- 17. 如何將PDCurses鏈接到Windows上的C++應用程序?
- 18. 將Windows Phone應用程序連接到網站?
- 19. 如何將GWT網站連接到Android應用程序?
- 20. 將Google+鏈接添加到我的通用網站
- 21. 如何將我的應用程序鏈接到iphone日曆
- 22. 在我的網站上運行python,C,C++應用程序
- 23. 我的Android應用程序共享我的應用程序鏈接到其他應用程序不起作用
- 24. 通過應用程序在網站上打開鏈接
- 25. 鏈接可可桌面應用程序和RubyonRails網站
- 26. iPhone應用程序:我可以通過網站中的鏈接打開應用程序嗎?
- 27. 使用應用程序瀏覽網站
- 28. 使用g ++編譯器(Ubuntu)將Allegro庫鏈接到C++應用程序
- 29. 分享網站鏈接什麼應用程序使用android工作室
- 30. 您可以深入鏈接到Squarespace託管網站的應用程序嗎?
使用`WebClient`。 – SLaks 2011-02-18 00:18:24
是的,這也是可能的http://stackoverflow.com/questions/1694388/webclient-vs-httpwebrequest-httpwebresponse – 2011-02-18 00:20:31