惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
P
Proofpoint News Feed
D
Docker
The Hacker News
The Hacker News
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
GbyAI
GbyAI
Jina AI
Jina AI
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
博客园 - 叶小钗
U
Unit 42
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
Latest news
Latest news
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
T
Threatpost
V
Vulnerabilities – Threatpost
C
Cisco Blogs
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
G
GRAHAM CLULEY
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
G
Google Developers Blog
Know Your Adversary
Know Your Adversary
F
Fortinet All Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Announcements
Recent Announcements
量子位
S
Schneier on Security
I
Intezer
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - roboth

转:“由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值”的解决方法 .net tostring format格式说明 - roboth 一、DIP简介(DIP--Dependency Inversion Principle): 请确认 &lt;Import&gt; 声明中的路径正确,且磁盘上存在该文件。 异步委托 Visual Studio 最常用的13个快捷键 H1N1:速饮配方 通过注册表获取文件的ContentType [转]解决ASP.NET Web Applicatio超时时间已到.在操作完成之前超时时间已过或服务器未响应 - roboth 在线创建pdf msdn之sp_xml_preparedocument Route命令使用详解 电子书下载 买药记 xslt之<xsl:apply-templates - roboth - 博客园 盲人摸象 sql产生日历表 dom操作时机 js小技巧之访问元素属性
抓取图片
roboth · 2009-05-21 · via 博客园 - roboth


using System;
using System.Collections.Generic;
using System.Linq;
using System.
Text;
using System.Net;
using System.
Text.RegularExpressions;
using System.IO;
namespace ImgSnatch
{
    class Program
    {
        static void Main(string
[] args)
        {
            Pic_Remote("
<img src=http://www.google.cn/images/nav_logo4.png>");
        }
        private static string Pic_Remote(string news_Content)
        {
            string htmlStr 
= news_Content;
            string nowyymm 
= DateTime.Now.ToString("yyyy-MM");    //当前年月
            string nowdd 
= DateTime.Now.ToString("dd"); //当天号数
            string path
=string.Format(@"d:\imgSnatch\images\{0}\{1}",nowyymm,nowdd);
            Directory.CreateDirectory(path);
            string returnValue 
= "";
            returnValue 
= SaveUrlPics(htmlStr, path, nowyymm, nowdd);
            
return returnValue;
        }
        
//下载图片到本地
        
public static string SaveUrlPics(string strHTML, string path, string nowyymm, string nowdd)
        {
            string
[] imgurlAry = GetImgTag(strHTML);
            try
            {
                
for (int i = 0; i < imgurlAry.Length; i++)
                {
                    
//WebRequest req = WebRequest.Create(imgurlAry[i]);
                    string preStr 
= System.DateTime.Now.ToString() + "_";
                    preStr 
= preStr.Replace("-", "");
                    preStr 
= preStr.Replace(":", "");
                    preStr 
= preStr.Replace(" ", "");
                    WebClient wc 
= new WebClient();
                    wc.DownloadFile(imgurlAry
[i], path + "/+ preStr + imgurlAry[i].Substring(imgurlAry[i].LastIndexOf("/") + 1));
                    
//替换原图片地址
                    string imgPath 
= "/Files/Remoteupfile/+ nowyymm + "/+ nowdd;
                    strHTML 
= strHTML.Replace(imgurlAry[i], imgPath + "/+ preStr + imgurlAry[i].Substring(imgurlAry[i].LastIndexOf("/") + 1));
                }
            }
            catch (Exception ex)
            {
                
//return ex.Message;
            }
            
return strHTML;
        }
//获取图片标志
        private static  string
[] GetImgTag(string htmlStr)
        {
            Regex regObj 
= new Regex("<img.+?>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            string
[] strAry = new string[regObj.Matches(htmlStr).Count];
            
int i = 0;
            foreach (Match matchItem 
in regObj.Matches(htmlStr))
            {
                strAry
[i] = GetImgUrl(matchItem.Value);
                i
++;
            }
            
return strAry;
        }
        
//获取图片URL地址
        private static  string GetImgUrl(string imgTagStr)
        {
            string 
str = "";
            Regex regObj 
= new Regex("http://.+.(?:jpg|gif|bmp|png)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            foreach (Match matchItem 
in regObj.Matches(imgTagStr))
            {
                
str = matchItem.Value;
            }
            
return str;
        }
    }
}