c#實現(xiàn)抓取高清美女妹紙圖片
更新時間:2015年03月11日 16:14:19 投稿:hebedich
本文給大家分享的是一則使用c#實現(xiàn)抓取網(wǎng)絡(luò)高清美女妹紙圖片的代碼,這么好的東西,當然不能獨享,推薦給小伙伴們。
c#實現(xiàn)抓取高清美女妹紙圖片
復(fù)制代碼 代碼如下:
private void DoFetch(int pageNum)
{
ThreadPool.QueueUserWorkItem(_ =>
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(" request.Credentials = System.Net.CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
List<Uri> links = FetchLinksFromSource(sr.ReadToEnd());
Console.WriteLine("=========================" + pageNum + "fatch END==========================");
}
}
});
}
private List<Uri> FetchLinksFromSource(string htmlSource)
{
List<Uri> links = new List<Uri>();
string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
MatchCollection matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
foreach (Match m in matchesImgSrc)
{
string href = m.Groups[1].Value;
if (CheckIsUrlFormat(href))
{
links.Add(new Uri(href));
Console.WriteLine(href);
}
else
continue;
using (WebClient myWebClient = new WebClient())
{
try
{
myWebClient.DownloadFile(new Uri(href), System.IO.Path.Combine(globePath, System.IO.Path.GetRandomFileName() + System.IO.Path.GetExtension(href)));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
return links;
}
以上就是本文的全部內(nèi)容了,大家可以自由擴展哦,你懂得,希望大家能夠喜歡。
相關(guān)文章
WPF自定義控件實現(xiàn)ItemsControl魚眼效果
這篇文章主要為大家詳細介紹了WPF如何通過自定義控件實現(xiàn)ItemsControl魚眼效果,文中的示例代碼講解詳細,需要的可以參考一下2024-01-01c#數(shù)據(jù)庫與TXT導(dǎo)入導(dǎo)出的實例
最近剛學完ADO.NET,做了個數(shù)據(jù)導(dǎo)入導(dǎo)出的題目,是將txt中的數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫,然后將數(shù)據(jù)庫中的數(shù)據(jù)導(dǎo)出到txt中,這里說的數(shù)據(jù)的格式是“tom|23”,tom指名字,23指年齡。廢話也不多說了,大家直接看代碼。2013-04-04