图片抓取器web + winform
原文发布时间为:2009-11-21 —— 来源于本人的百度文章 [由搬家工具导入]
请先学习:http://hi.baidu.com/handboy/blog/item/bfef61000a67ea16738b6565.html
string x = "Live for nothing,die for something";
Regex r = new Regex(@"^Live for no(?<g1>[a-z]{5}),die for some\1$");
if (r.IsMatch(x))
{
Console.WriteLine("group1 value:" + r.Match(x).Groups["g1"].Value);//输出:thing
}
//可根据组名进行索引。使用以下格式为标识一个组的名称(?<groupname>…)。
string x = "Live for nothing nothing";
Regex r = new Regex(@"([a-z]+) \1");
if (r.IsMatch(x))
{
x = r.Replace(x, "$1");
Console.WriteLine("var x:" + x);//输出:Live for nothing
}
//删除原字符串中重复出现的“nothing”。在表达式之外,使用“$1”来引用第一个组,下面则是通过
组名来引用:
string x = "Live for nothing nothing";
Regex r = new Regex(@"(?<g1>[a-z]+) \1");
if (r.IsMatch(x))
{
x = r.Replace(x, "${g1}");
Console.WriteLine("var x:" + x);//输出:Live for nothing
}
string x = "Live for nothing";
Regex r = new Regex(@"^Live for no(?:[a-z]{5})$");
if (r.IsMatch(x))
{
Console.WriteLine("group1 value:" + r.Match(x).Groups[1].Value);//输出:(空)
}
//在组前加上“?:”表示这是个“非捕获组”,即引擎将不保存该组的内容。
========
最近闲来无事,重温了一下正则表达式,然后做了这个 图片抓取器。
原则就是 根据分析 新浪博文的共同特征,把图片抓取到本地下来,自动下载下来。 这个原理就是用 正则表达式去匹配,如果有一天新浪博文网页格式变化了,可能这个就用不了了,但是可以进行修改去满足。这只是一个范例,O(∩_∩)O哈!
winform下载预览:http://www.xmaspx.com/Services/FileAttachment.ashx?AttachmentID=51
首先:
在根目录下,建一个名为 DownLoadImages 的文件夹
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SinaImage.aspx.cs" Inherits="SinaImage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="495px">http://blog.sina.com.cn/s/articlelist_1270540911_0_1.html</asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="javascript:alert('开始下载,可能要等几分钟,请勿关闭')" /><br />
<asp:TextBox ID="TextBox2" runat="server" Height="296px" TextMode="MultiLine" Width="498px"></asp:TextBox></div>
</form>
</body>
</html>
后台:
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;
public partial class SinaImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int num = 0;
TextBox2.Text = "";
string p = @"http://blog.sina.com.cn/s/blog_([\w])*.html";
string p2 = @"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
ArrayList arrUrl = GetUrl(this.TextBox1.Text, p);
for (int i = 0; i < arrUrl.Count; i++)
{
string imgPage = arrUrl[i].ToString();
ArrayList arrImgUrl = GetUrl(imgPage, p2);
for (int j = 0; j < arrImgUrl.Count; j++)
{
string imgUrl = arrImgUrl[j].ToString();
if (!imgUrl.Contains("simg") && !imgUrl.Contains("sinaimg") && !imgUrl.Contains(".js"))
{
if (imgUrl.Contains("photo") || imgUrl.Contains("image") || imgUrl.Contains("img"))
{
TextBox2.Text += imgUrl + "\n";
try
{
DownLoadImage(imgUrl, j.ToString());
num++;
}
catch
{
}
}
}
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('下载了" + num.ToString() + "张,请打开文件夹DownLoadImages,以缩略图形式进行筛选')", true);
}
protected void DownLoadImage(string fromUrl, string fileName)
{
string savePath = Server.MapPath("DownLoadImages/") + DateTime.Now.ToString("yyyyMMddhhmmss") + fileName + ".jpg";
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(fromUrl, savePath);
}
protected ArrayList GetUrl(string web_url, string p)
{
string all_code = string.Empty;
ArrayList arrUrl = new ArrayList();
HttpWebRequest all_codeRequest = (HttpWebRequest)WebRequest.Create(web_url);
WebResponse all_codeResponse = all_codeRequest.GetResponse();
StreamReader the_Reader = new StreamReader(all_codeResponse.GetResponseStream(), Encoding.GetEncoding("GB2312"));
all_code = the_Reader.ReadToEnd();
the_Reader.Close();
ArrayList my_list = new ArrayList();
Regex re = new Regex(p, RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(all_code);
for (int i = 0; i <= mc.Count - 1; i++)
{
bool _foo = false;
string name = mc[i].ToString();
foreach (string list in my_list)
{
if (name == list)
{
_foo = true;
break;
}
}//过滤
if (!_foo)
{
arrUrl.Add(name);
}
}
return arrUrl;
}
}
图片抓取器web + winform的更多相关文章
- [转]使用Scrapy建立一个网站抓取器
英文原文:Build a Website Crawler based upon Scrapy 标签: Scrapy Python 209人收藏此文章, 我要收藏renwofei423 推荐于 11个月 ...
- [python应用]python简单图片抓取
前言 emmmm python简单图片抓取 1 import requests 2 import threading 3 import queue 4 from subprocess import P ...
- php远程图片抓取存放到本地路径并生成缩略图
private function _getcontent($content) { $img_dir='../Public/Img/Ycimg'; //远程图片抓取存放 ...
- 联系我们_鲲鹏Web数据抓取 - 专业Web数据采集服务提供者
联系我们_鲲鹏Web数据抓取 - 专业Web数据采集服务提供者 首页 > 联系我们 我们的联系方式如下: 029 - 82542052(陕西 西安) 13389148466 或 13571845 ...
- arpspoof+driftnet+ ARP欺骗简单图片抓取
arpspoof+driftnet+ ARP欺骗简单图片抓取 driftnet是一款简单而使用的图片捕获工具,可以很方便的在网络数据包中抓取图片.该工具可以实时和离线捕获指定数据包中是图片 环境 受害 ...
- Python爬虫入门教程 25-100 知乎文章图片爬取器之一
1. 知乎文章图片写在前面 今天开始尝试爬取一下知乎,看一下这个网站都有什么好玩的内容可以爬取到,可能断断续续会写几篇文章,今天首先爬取最简单的,单一文章的所有回答,爬取这个没有什么难度. 找到我们要 ...
- Python selenium自动化网页抓取器
(开开心心每一天~ ---虫瘾师) 直接入正题---Python selenium自动控制浏览器对网页的数据进行抓取,其中包含按钮点击.跳转页面.搜索框的输入.页面的价值数据存储.mongodb自动i ...
- 简易数据分析 09 | Web Scraper 自动控制抓取数量 & Web Scraper 父子选择器
这是简易数据分析系列的第 9 篇文章. 今天我们说说 Web Scraper 的一些小功能:自动控制 Web Scraper 抓取数量和 Web Scraper 的父子选择器. 如何只抓取前 100 ...
- C#实现通过程序自动抓取远程Web网页信息的代码
http://www.jb51.net/article/9499.htm 通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在 ...
随机推荐
- Linux运维常用命令详解
1.ls 文件属性: -:普通文件 d:目录文件 b:块设备 c:字符设备文件 l:符号连接文件 p:命令管道 s:套接字文件 文件权限: 9位数字,每3位一组 文件硬链接次数 文 ...
- webpack+thymeleaf实现数据直出
webpack动态插入thymeleaf模板,MVC将要使用数据传递到模板中渲染,得到的html就已经带有要初始显示的数据了github:https://github.com/947133297/we ...
- phpspider案例
phpspider案例 <?php require './autoload.php'; use phpspider\core\phpspider; /* Do NOT delete this c ...
- yii2 RUL的生成
通常情况下,会使用 yii\helpers\Url 使用Url类来生成想要的URL地址(链接) Url提供的方法大都是静态方法,不需要对类进行实例化 1.1 最常用的 Url::to() 1.2. b ...
- python3 练习题100例 (十三)
题目十三:将一个正整数分解质因数.例如:输入60,打印出60=2*2*3*5. #!/usr/bin/env python3 # -*- coding: utf-8 -*- ""& ...
- Harbor HA部署-使用Ceph RADOS后端
1. 前言 Harbor 1.4.0版本开始提供了HA部署方式,和非HA的主要区别就是把有状态的服务分离出来,使用外部集群,而不是运行在本地的容器上.而无状态的服务则可以部署在多个节点上,通过配置上层 ...
- Python及其常用模块库下载及安装
一.Python下载:https://www.python.org/downloads/ 二.Python模块下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...
- ogre3D学习基础14 -- 雾化效果与天空面,天空盒,天空穹
前几天设置天空盒时一直出问题,现在问题终于解决了,问题来的莫名其妙,走的也莫名其妙. 第一,还是框架,我们依然使用ExampleApplication文件,框架如下 #include "Ex ...
- c++ primer plus 第6版 部分一 1-4章
c++ primer plus 第6版 源代码 ---编译器---目标代码---连接程序(启动代码--库代码)---可执行代码 源代码扩展名:c cc cxx C cpp ...
- Jquery版放大镜效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...