软件介绍

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:盘目录下是否存在
 

操作演示

代码示例

#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) > -1 ||
url.IndexOf("https://", StringComparison.OrdinalIgnoreCase) > -1) ? 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) > -1 ||
url.IndexOf("https://", StringComparison.OrdinalIgnoreCase) > -1) ? 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 > 0 ? info.WaitForExitTime : 6000);
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

【C#】NET截屏网页,生成网页快照开发——IECapt、CutyCapt的更多相关文章

  1. LINUX下PHP网页生成快照(截屏)(xvfb and wkhtmltoimage)

    经测试,可以使用 利用php截屏或实现网页快照我们需要用一个工具:xvfb and wkhtmltoimagek哦,这个工具目前只能在linux系统中使用,下面有兴趣的朋友可进入参考. 在做旅游攻略时 ...

  2. Android 截屏与 WebView 长图分享经验总结

    最近在做新业务需求的同时,我们在 Android 上遇到了一些之前没有碰到过的问题,截屏分享. WebView 生成长图以及长图在各个分享渠道分享时图片模糊甚至分享失败等问题,在这过程中踩了很多坑,到 ...

  3. IECapt、CutyCapt 生成网页快照

    IECapt.CutyCapt  生成网页快照 http://iecapt.sourceforge.net/ http://cutycapt.sourceforge.net/ 1.以管理员身份 运行c ...

  4. Javascript网页截屏的方法

    最近我在研究开发一个火狐插件,具体的功能是将网页内容截屏并分享到微博上.目前基本功能已经实现,大家可以在 @程序师视野 里看到用这个截图插件分享的微博的效果. 之前我曾写过如何将canvas图形转换成 ...

  5. C#使用phantomjs 进行网页整页截屏

    C#使用phantomjs 进行网页整页截屏 hantomjs 是一个基于js的webkit内核无头浏览器 也就是没有显示界面的浏览器,这样访问网页就省去了浏览器的界面绘制所消耗的系统资源,比较适合用 ...

  6. js利用clipboardData在网页中实现截屏粘贴的功能

    目前仅有高版本的 Chrome 浏览器支持这样直接粘贴,其他浏览器目前为止还无法粘贴,不过火狐和ie11浏览器在可编辑的div中能够粘贴截图的图片也是base64位和Chrome利用clipboard ...

  7. JS实现网页选取截屏 保存+打印 功能(转)

    源码地址: 1.1 确定截图选取范围 用户在开始截图后,需要在页面上选取一个截图范围,并且可以直观的看到,类似如下效果: image 我们的选取范围就是鼠标开始按下的那个点到鼠标拖动然后松开的那个点之 ...

  8. 利用PhantomJS进行网页截屏,完美解决截取高度的问题

    关于PhantomJS PhantomJS 是一个基于WebKit的服务器端 JavaScript API.它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS ...

  9. PhantomJS linux系统下安装步骤及使用方法(网页截屏功能)

    PhantomJS 是一个基于 WebKit 的服务器端 JavaScript API.它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, JSON, ...

随机推荐

  1. vc6.0创建文件时,出现很多烫烫烫解决方法

    vc6.0创建文件时,出现很多烫烫烫烫解决方法 SWM2烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫.IA 如果项目文件放在桌面上 如:C:\Documents and Settings\txwtec ...

  2. 记录工作中遇到的BUG,经典的数据库时区问题和字段类型tinyint(1)问题

    记录工作中发现的相对而言经典的问题 [数据库时区问题] 我个人数据库配置为CST 如下 我们测试环境的数据库配置为UTC 如下 倘若我修改了测试环境数据库时区为CST.由此造成的问题是 系统读取到数据 ...

  3. 多语言工作者の十日冲刺<5/10>

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺--第五天(05.04) 作业正文 ...

  4. 30_栈的定义.swf

    上面的局部变量 i int*p中的p指针变量,是在栈中分配的,malloc申请的内存是在堆中分配的,动态申请的都在堆中分配的. 栈是一种数据存储的结果,先进后出的数据结构.

  5. android 抓取native层奔溃

    使用android的breakpad工具 使用这个工具需要下载Breakpad的源码,然后进行编译,编译之后会生成两个工具 我们使用这两个工具来解析奔溃的位置.这里我们可以下载已经编译好的工具 下载地 ...

  6. ATM项目分析

    ATM项目分析 项目源代码下载 其实本项目的需求分析乍一看比较复杂,但是细细拆分出来实际实现还是比较容易的.基本用上前面所学的所有知识点. 1.额度 15000或自定义 2.实现购物商场,买东西加入购 ...

  7. 入门大数据---Elasticsearch是什么?

    Elasticsearch是谁不重要,重要的是咱们都知道百度,谷歌这样的搜索巨头吧.它们的核心技术都利用了Elasticsearch,所以我们有必要对Elasticsearch了解下! 1.Elast ...

  8. js事件入门(3)

    3.键盘事件 3.1.onkeydown 键盘按下事件 当键盘按下的时候触发 <!DOCTYPE html> <html> <head> <meta char ...

  9. oracle如何实现自增?----用序列sequence的方法来实现

    将表t_user的字段ID设置为自增:(用序列sequence的方法来实现) ----创建表 Create  table  t_user( Id number(6),userid varchar2(2 ...

  10. 控制shell终端提示符格式和颜色

    字体颜色值 (ASCII) 背景颜色值 (ASCII) 显示颜色 30 40 黑色 31 41 红色 32 42 绿色 33 43 黄色 34 44 蓝色 35 45 紫红色 36 46 青蓝色 37 ...