IECapt、CutyCapt 生成网页快照
IECapt、CutyCapt 生成网页快照
http://iecapt.sourceforge.net/
http://cutycapt.sourceforge.net/
1.以管理员身份 运行cmd.exe 切换到 IECapt.exe 所在目录
例如:
输入:D:
输入:cd D:\AppData\
输入截图命令:
输入:CutyCapt --url=https://tieba.baidu.com/p/5217647622 --out=D:/1.jpeg --silent
输入:iecapt --url=https://tieba.baidu.com/p/5217647622 --out=D:/1.jpeg --silent
看下D:盘目录下是否存在

一下面是 c#代码:
#region CutyCapt
//Open a command prompt and ask for help: // % CutyCapt --help
// -----------------------------------------------------------------------------
// Usage: CutyCapt --url=http://www.example.org/ --out=localfile.png
// -----------------------------------------------------------------------------
// --help Print this help page and exit
// --url=< url > The URL to capture (http:...|file:...|...)
// --out=<path> The target file (.png|pdf|ps|svg|jpeg|...)
// --out-format=<f> Like extension in --out, overrides heuristic
// --min-width=<int> Minimal width for the image (default: 800)
// --min-height=<int> Minimal height for the image (default: 600)
// --max-wait=<ms> Don't wait more than (default: 90000, inf: 0)
// --delay=<ms> After successful load, wait (default: 0)
// --user-style-path=<path> Location of user style sheet file, if any
// --user-style-string=<css> User style rules specified as text
// --header=<name>:<value> request header; repeatable; some can't be set
// --method=<get| post | put > Specifies the request method(default: get)
// --body - string =< string > Unencoded request body(default: none)
// --body - base64 =< base64 > Base64 - encoded request body(default: none)
// --app - name =< name > appName used in User - Agent;
// default is none
// --app - version =< version > appVers used in User - Agent;
// default is none
// --user - agent =< string > Override the User-Agent header Qt would set
// --javascript =< on | off > JavaScript execution(default: on)
// --java =< on | off > Java execution(default: unknown)
// --plugins =< on | off > Plugin execution(default: unknown)
// --private-browsing=<on|off> Private browsing(default: unknown)
// --auto-load-images=<on|off> Automatic image loading(default: on)
// --js-can-open-windows=<on|off> Script can open windows? (default: unknown)
// --js-can-access-clipboard=<on|off> Script clipboard privs(default: unknown)
// --print-backgrounds=<on|off> Backgrounds in PDF/PS output(default: off)
// --zoom-factor=<float> Page zoom factor(default: no zooming)
// --zoom-text-only=<on|off> Whether to zoom only the text(default: off)
// --http-proxy=<url> Address for HTTP proxy server(default: none)
// -----------------------------------------------------------------------------
// <f> is svg,ps,pdf,itext,html,rtree,png,jpeg,mng,tiff,gif,bmp,ppm,xbm,xpm
// -----------------------------------------------------------------------------
// http://cutycapt.sf.net - (c) 2003-2013 Bjoern Hoehrmann - bjoern@hoehrmann.de
#endregion
#region IECapt
// Open a command prompt and ask for help:
//C:\> IECapt --help
// -----------------------------------------------------------------------------
// Usage: IECapt --url=http://www.example.org/ --out=localfile.png
// -----------------------------------------------------------------------------
// --help Print this help page and exit
// --url=<url> The URL to capture (http:...|file:...|...)
// --out=<path> The target file (.png|bmp|jpeg|emf|...)
// --min-width=<int> Minimal width for the image (default: 800)
// --max-wait=<ms> Don't wait more than (default: 90000, inf: 0)
// --delay=<ms> Wait after loading (e.g. for Flash; default: 0)
// --silent Whether to surpress some dialogs
// -----------------------------------------------------------------------------
// http://iecapt.sf.net - (c) 2003-2008 Bjoern Hoehrmann - <bjoern@hoehrmann.de>"/>
#endregion using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web; namespace Capt.Helper
{ public class CaptHelper
{
/// <summary>
/// 执行截图操作
/// </summary>
/// <param name="url">网页链接,example:"https://www.baidu.com/"</param>
/// <returns></returns>
public static ReturnResult<string> Execute(string url, IECaptOrCutyCapt type = IECaptOrCutyCapt.IECapt)
{
if (string.IsNullOrEmpty(url))
{
return new ReturnResult<string>() { Msg = "url 为空" };
}
url = (url.IndexOf("http://", StringComparison.OrdinalIgnoreCase) > - ||
url.IndexOf("https://", StringComparison.OrdinalIgnoreCase) > -) ? url : "http://" + url;
var path = AppDomain.CurrentDomain.BaseDirectory + "TempFiles\\Image";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string fileName = Guid.NewGuid().ToString("N") + ".png";
string completePath = Path.Combine(path, fileName);
var data = Execute(new CaptInfo() { Url = url, Out = completePath, CaptType = type });
data.Data = completePath;
return data;
}
/// <summary>
/// 执行截图操作
/// </summary>
/// <param name="url"></param>
/// <param name="path">物理路径,</param>
/// <returns></returns>
public static ReturnResult<string> Execute(string url, string path,
IECaptOrCutyCapt type = IECaptOrCutyCapt.IECapt)
{
if (string.IsNullOrEmpty(url))
{
return new ReturnResult<string>() { Msg = "url 为空" };
}
url = (url.IndexOf("http://", StringComparison.OrdinalIgnoreCase) > - ||
url.IndexOf("https://", StringComparison.OrdinalIgnoreCase) > -) ? url : "http://" + url; if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileName = Guid.NewGuid().ToString("N") + ".png";
string completePath = Path.Combine(path, fileName);
var data = Execute(new CaptInfo() { Url = url, Out = completePath, CaptType = type });
data.Data = completePath;
return data;
}
/// <summary>
/// 执行输出快照
/// </summary>
/// <param name="info">CaptInfo</param>
/// <returns></returns>
public static ReturnResult<string> Execute(CaptInfo info)
{
string output = string.Empty;
Stopwatch sw = Stopwatch.StartNew();
string root = string.Empty;
if (info.CaptType == IECaptOrCutyCapt.IECapt)
{
root = AppDomain.CurrentDomain.BaseDirectory + @"Lib\\IECapt";
if (!File.Exists(root + "\\IECapt.exe"))
throw new FileNotFoundException("IECapt.exe file can't be found .");
}
else
{
root = AppDomain.CurrentDomain.BaseDirectory + @"Lib\\CutyCapt";
if (!File.Exists(root + "\\CutyCapt.exe"))
throw new FileNotFoundException("IECapt.exe file can't be found .");
} using (var process = new Process())
{
try
{
process.StartInfo.WorkingDirectory = root;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true; //process.StartInfo.CreateNoWindow = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
string value = string.Format(@"{0} --url={1} --out={2} --min-width={3} --max-wait={4} --delay={5} --silent",
info.CaptType == IECaptOrCutyCapt.IECapt ? "iecapt" : "cutycapt", //输出方式
info.Url, //输入路径网站
info.Out, //输出
info.Min_width,
info.Max_wait,
info.Delay);
process.StandardInput.WriteLine(value);
process.StandardInput.WriteLine("exit");
process.WaitForExit(info.WaitForExitTime > ? info.WaitForExitTime : );
output = process.StandardOutput.ReadToEnd(); }
catch (Exception ex)
{
return new ReturnResult<string>()
{
Status = CaptStatus.ErrorException,
Msg = "快照失败:" + ex.Message
};
}
finally
{
sw.Stop();
if (!process.HasExited)
{
process.Kill();
}
process.Close();
process.Dispose(); }
if (System.IO.File.Exists(info.Out))
{
return new ReturnResult<string>()
{
Status = CaptStatus.Success,
QTime = sw.ElapsedMilliseconds,
Msg = "快照生产成功:" + output
};
}
else
{
return new ReturnResult<string>()
{
Status = CaptStatus.ErrorNotOutFile,
Msg = "快照失败,文件不存在"
};
} }
} }
}
源码地址:https://github.com/Sopcce/IECapt.Net
IECapt、CutyCapt 生成网页快照的更多相关文章
- 【C#】NET截屏网页,生成网页快照开发——IECapt、CutyCapt
软件介绍 IECapt.CutyCapt 生成网页快照 http://iecapt.sourceforge.net/ http://cutycapt.sourceforge.net/ ### 操作代码 ...
- PHP CutyCapt生成网页url截图
Requirements: 1,需要一个linux系统. 2, X-Server.(在命令行下实现对X-server的模拟,渲染图形进行缓存)-在没有安装X-Server的环境下提供图像渲染) Age ...
- .net mvc C#生成网页快照
目标:调用某一网页,自动抓取整个页面为图片,并保存 public class WebSiteThumbnail { Bitmap m_Bitmap; string m_Url; public WebS ...
- C#实现HTML转图片(网页快照)
有时候我们需要将网页转成图片,那么可以使用WebBrowser来生成网页快照,废话不多说,代码如下 1.网页快照帮助类(如果是BS或控制台需要引用System.Windows.Forms类库): pu ...
- Puppeteer - 谷歌推出的自动化测试工具库
Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制无头 Chrome 或 Chromium.它允许你从浏览器之外的环境(即命令行)与Chromium ...
- Google Hacking 搜索引擎攻击与防范
Google Hacking,有时也会被称为 Google dorking,是一种利用谷歌搜索的高级使用方式进行信息收集的技术.这个概念最早在2000年由黑客 Johnny Long 提出并推广,一系 ...
- Oracle 11g数据库详解(2)
FAILED_LOGIN_ATTEMPTS 用于指定连续登陆失败的最大次数 达到最大次数后,用户会被锁定,登陆时提示ORA-28000 UNLIMITED为不限制 精确无误差 是 实时 PASSWOR ...
- linux命令行抓取网页快照-(xvfb+CutyCapt)
目的: 在一台没有安装X-server的Debian服务器上实现命令行抓取网页快照 软件: xvfb(在命令行下实现对X-server的模拟,渲染图形进行缓存)-在没有安装X-Server的环境下提供 ...
- [转]Phantomjs实现获取网页快照并生成缩略图
Shell脚本实现获取网页快照并生成缩略图 这篇文章主要介绍了Shell脚本实现获取网页快照并生成缩略图,本文获取网页快照使用phantomjs.生成缩略图使用ImageMagick,需要的朋友可以参 ...
随机推荐
- Kafka命令行常用命令说明
基于0.8.0版本. ##查看topic分布情况kafka-list-topic.sh bin/kafka-list-topic.sh --zookeeper 192.168.197.170:2181 ...
- XAMPP非本地访问被拒绝解决办法
问题场景: 本机搭建一个apache服务器,正常访问XAMPP目录下的页面. 手机接入同一wifi,以电脑ip方式访问该目录下的页面:提示:Access Denied Access to the re ...
- advance shading--光源的类型
我们这里讨论的光源类型都有一个相同点,就是,我们考量的都是光源上的一个点,对于物体表面上一个点的影响,也就是说立体角趋近为零的情况. 这里光源分为两类,一类是方向光,假设光源在无限远处.另一类是点光源 ...
- tab切换代码优化
上次的tab切换的代码里面有很多重复的代码,需要做做优化,把重复的代码用函数封装起来调用. 优化前: <script> //获取id封装成一个函数$()方便调用 function $(id ...
- Hdu1547 Bubble Shooter 2017-01-20 18:38 44人阅读 评论(0) 收藏
Bubble Shooter Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- CYUSB3014芯片使用EEPROM无法下载固件说明
当使用128KB的EEPROM存储CYUSB3014芯片的固件时,需要注意,不同厂家的EEPROM存储器,其A0.A1.A2功能不一样,在设计时电路也不一样.Microchip对应的128KB的EEP ...
- ServiceStack.Text json中序列化日期格式问题的解决
标记: ServiceStack.Text,json,序列化,日期 在使用ServiceStack.Text的序列化为json格式的时候,当属性为datetime的时候,返回的是一个new date( ...
- PostgreSQL查询数据(基本查询)
原料:数据表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ) ...
- 2:C#TPL探秘
理论: 1. 只要方法是 Task类型的返回值,都可以用 await 来等待调用获取返回值. 2. 如果一个返回 Task类型的方法被标记了 async,那么只要方法内部直接 return T 这个 ...
- wpf(怎么跨线程访问wpf控件)
在编写代码时,我们经常会碰到一些子线程中处理完的信息,需要通知另一个线程(我这边处理完了,该你了). 但是当我们通知WPF的UI线程时需要用到Dispatcher. 首先我们需要想好在UI控件上需要显 ...