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

推荐订阅源

博客园 - 聂微东
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Vercel News
Vercel News
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Jina AI
Jina AI
B
Blog
Recorded Future
Recorded Future
MyScale Blog
MyScale Blog
I
InfoQ
aimingoo的专栏
aimingoo的专栏
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
爱范儿
爱范儿
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
博客园 - Franky
Schneier on Security
Schneier on Security
V
V2EX
TaoSecurity Blog
TaoSecurity Blog
H
Hacker News: Front Page
Cloudbric
Cloudbric
D
DataBreaches.Net
B
Blog RSS Feed
P
Palo Alto Networks Blog
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
I
Intezer
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyberwarzone
Cyberwarzone
F
Fortinet All Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
K
Kaspersky official blog
Forbes - Security
Forbes - Security

博客园 - BigRain

小学生学习汉字,汉字抓取 c# regex regextools cache 访问频率的思考 python 百度cpc点击 20130118SQL记录 PPT辅助工具 webService启用cookie的另一种方法 百度调价HttpWebRequest 装饰者模式 第一个android程序闪亮登场 SQL 的一些批量插入和修改 职责链模式的运用 State Pattern 程序人生 SerialPort实现modem的来电显示 利用枚举进行状态的设计 singleton模式 在软件开发中的运用 我对当前项目的一些看法 闲话闲说——关于异常
检查外链的方法
BigRain · 2012-06-14 · via 博客园 - BigRain
private void Check()
        {
            int currentNum = CurrentNum;
            if (currentNum >= totalCount)
            {
                return;
            }
            DataGridViewRow row = this.dataGridView1.Rows[currentNum];
            row.Cells["ID"].Style.BackColor = Color.Green;
            string url = row.Cells["URL"].Value.ToString();
            string title = row.Cells["Title"].Value.ToString();
            title = System.Web.HttpUtility.HtmlEncode(title);
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            Uri uri = new Uri(url);
            System.IO.Stream stream = null; ;
            try
            {
                stream = client.OpenRead(uri);
            }
            catch (System.Net.WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                if (ex.Status == WebExceptionStatus.ConnectFailure)
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                if (ex.Status == WebExceptionStatus.Timeout)
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                if (stream != null)
                    stream.Dispose();
                client.Dispose();
                return;
            }

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                int len = 0;
                byte[] buff = new byte[512];
                while ((len = stream.Read(buff, 0, 512)) > 0)
                {
                    ms.Write(buff, 0, len);
                }
                string content = System.Text.Encoding.UTF8.GetString(ms.ToArray());
                Match charSetMatch = Regex.Match(content, "<meta([^<]*)charset=\"?'?([^<]*)\"", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                string encoding = charSetMatch.Groups[2].Value;
                if (string.IsNullOrEmpty(encoding))
                {
                    encoding = client.ResponseHeaders[HttpResponseHeader.ContentEncoding];
                }
                if (!string.IsNullOrEmpty(encoding) && encoding.ToLower() != "utf-8")
                {
                    if (encoding.ToLower().Contains("gzip"))
                    {
                        using (System.IO.MemoryStream memory = new System.IO.MemoryStream())
                        {
                            ms.Position = 0L;
                            using (GZipStream gZipStream = new GZipStream(ms, CompressionMode.Decompress))
                            {
                                while ((len = gZipStream.Read(buff, 0, 512)) > 0)
                                {
                                    memory.Write(buff, 0, len);
                                }
                            }
                            content = System.Text.Encoding.UTF8.GetString(memory.ToArray());
                        }

                    }
                    else
                    {
                        try
                        {
                            if (encoding.ToLower().Contains("gbk"))
                                encoding = "gb2312";
                            content = System.Text.Encoding.GetEncoding(encoding).GetString(ms.ToArray());
                        }
                        catch
                        {
                        }
                    }
                }
                Match match = titleRegex.Match(content);
                if (!match.Success)
                {
                    row.DefaultCellStyle.BackColor = Color.FromArgb(255, 200, 200, 200);
                }
                else if (content.IndexOf(title) < 0)
                {
                    row.DefaultCellStyle.BackColor = Color.FromArgb(255, 200, 200, 200);
                }
            }
            if (stream != null)
                stream.Dispose();
            row.Cells["ID"].Style.BackColor = Color.FromArgb(255, 108, 226, 108);
        }

最近工作需要,需要检查推广人员的工作情况,每天500条以上的外链,人工一条一条的检查实在不和谐。写了一个检查的程序,备份下。