找回密码
 立即注册
搜索
查看: 5506|回复: 28

[软件] [死程福利] 图片另存为?弱爆了

[复制链接]
     
发表于 2011-9-6 21:30 | 显示全部楼层 |阅读模式
EH收本用,死程向福利,自己下载去编译
不会编译自己学去[strike],软妹PM,面授可[/strike]
非死程慎用,bug一大堆,不会修的话拿去也是白拿[strike],软妹可提交bug[/strike]
程序做的无非就是这些事情:打开IE,等图片下载,保存图片,点击图片翻到下一页,循环往复至最后一页结束。没有任何多余的请求发到服务器

严重缺陷:运行期间会占用剪贴板,建议丢虚机里搞
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using System.Threading;
  8. using System.IO;
  9. using mshtml;
  10. using SHDocVw;
  11. using WatiN.Core;
  12. using WatiN.Core.Native;
  13. using WatiN.Core.Native.InternetExplorer;
  14. using WatiN.Core.Native.Windows;
  15. namespace EHentaiDownloader
  16. {
  17.     class Program
  18.     {
  19.         static string RemoveInvalidPathChars(string originalPath)
  20.         {
  21.             string invalidChars = new string(Path.GetInvalidPathChars());
  22.             string newPath = originalPath;
  23.             foreach (char c in invalidChars)
  24.             {
  25.                 newPath = newPath.Replace(c.ToString(), "");
  26.             }
  27.             return newPath;
  28.         }
  29.         static string GetScriptContent(int i)
  30.         {
  31.             string scriptContent =
  32. @"var div = document.images[" + i.ToString() + @"];
  33. div.contentEditable = 'true';
  34. var controlRange;
  35. if (document.body.createControlRange) {
  36. controlRange = document.body.createControlRange();
  37. controlRange.addElement(div);
  38. controlRange.execCommand('Copy');
  39. }
  40. div.contentEditable = 'false';";
  41.             return scriptContent;
  42.         }
  43.         [STAThread]
  44.         static void Main(string[] args)
  45.         {
  46.             const int sizeLimit = 500;
  47.             const int retryInterval = 500;
  48.             const int retryBeforeRefresh = 120 * 1000 / retryInterval;
  49.             int pageIndex;
  50.             var ie = new IE("about:blank");
  51.             if (args.Length == 2 && string.Compare("debug", args[1]) == 0)
  52.             {
  53.                 // DO NOTHING
  54.             }
  55.             else
  56.             {
  57.                 ie.ShowWindow(NativeMethods.WindowShowStyle.Hide);
  58.             }
  59.             if (args.Length != 1 && args.Length != 2)
  60.             {
  61.                 // Wrong parameters
  62.                 return;
  63.             }
  64.             else
  65.             {
  66.                 ie.GoTo(args[0]);
  67.             }
  68.             try
  69.             {
  70.                 string[] split = ie.Url.Split(new Char[] { '-', '_', ',' });
  71.                 pageIndex = int.Parse(split[split.Length - 1]);
  72.             }
  73.             catch (Exception ex)
  74.             {
  75.                 pageIndex = 1;
  76.             }
  77.             string lastUrl = ie.Url;
  78.             string dirTitle = ie.ElementsWithTag("h1")[0].OuterText;    // The first H1 is the title
  79.             if (dirTitle.Length == 0) { return; }
  80.             // Create/Change working directory here
  81.             try
  82.             {
  83.                 dirTitle = RemoveInvalidPathChars(dirTitle);
  84.                 if (!Directory.Exists(dirTitle))
  85.                 {
  86.                     Directory.CreateDirectory(dirTitle);
  87.                 }
  88.                 Directory.SetCurrentDirectory(dirTitle);
  89.             }
  90.             catch (Exception ex)
  91.             {
  92.                 Console.WriteLine(ex.Message);
  93.                 Console.WriteLine(dirTitle);
  94.                 return;
  95.             }
  96.             
  97.             do
  98.             {
  99.                 int imgCount = ie.Images.Count;
  100.                 int nextImage;
  101.                 nextImage = -1;
  102.                 for (int i = 0; i < imgCount; i++)
  103.                 {
  104.                     string scriptContent = GetScriptContent(i);
  105.                     bool downloadFinished = false;
  106.                     IDataObject data;
  107.                     int retryTimes = 0;
  108.                     while (!downloadFinished)
  109.                     {
  110.                         ie.RunScript(scriptContent);
  111.                         data = Clipboard.GetDataObject();
  112.                         if (data.GetDataPresent(DataFormats.Bitmap))
  113.                         {
  114.                             System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
  115.                             try
  116.                             {
  117.                                 if (image.Height > sizeLimit && image.Width > sizeLimit)
  118.                                 {
  119.                                     image.Save(pageIndex.ToString("D3") + ".png", System.Drawing.Imaging.ImageFormat.Png);
  120.                                     Console.WriteLine("Page #" + pageIndex.ToString() + " downloaded.");
  121.                                     pageIndex++;
  122.                                     nextImage = i;
  123.                                     downloadFinished = true;
  124.                                     break;
  125.                                 }
  126.                                 else
  127.                                 {
  128.                                     downloadFinished = true;
  129.                                 }
  130.                             }
  131.                             catch (Exception ex)
  132.                             {
  133.                             }
  134.                         }
  135.                         if (!downloadFinished)
  136.                         {
  137.                             Thread.Sleep(retryInterval);
  138.                             retryTimes++;
  139.                             if (retryTimes >= retryBeforeRefresh)
  140.                             {
  141.                                 ie.Refresh();
  142.                                 retryTimes = 0;
  143.                             }
  144.                         }
  145.                     }
  146.                 }
  147.                 if (nextImage != -1)
  148.                 {
  149.                     ie.Images[nextImage].Click();
  150.                 }
  151.                 if (string.Compare(ie.Url, lastUrl) == 0) break;
  152.                 lastUrl = ie.Url;
  153.             } while (true);
  154.             ie.Close();
  155.         }
  156.     }
  157. }
复制代码
回复

使用道具 举报

发表于 2011-9-6 22:15 | 显示全部楼层
玩玩hv会有多难
回复

使用道具 举报

发表于 2011-9-6 22:26 | 显示全部楼层
微软出过类似功能的软件,可以作为ie的插件来使用,可以全部保存页面中的图片,flash,可能还有视频和mp3,软件名字我忘了,就记得界面是橘黄色的,而且试用版有时间限制。
还有一个笨球的PhotoFamily 3.0,这是个相册制作软件,但我没用过它做相册。安装之后会在ie右键里添加发送所有图片至储存柜,可以设定小于多少的图片不要,基本保证收的都是你想要的。唯一缺点一次最多一百张
回复

使用道具 举报

     
 楼主| 发表于 2011-9-6 22:28 | 显示全部楼层
引用第1楼19407千里于2011-09-06 22:15发表的  :
玩玩hv会有多难

不难,费时间
回复

使用道具 举报

发表于 2011-9-6 22:29 | 显示全部楼层
ViewPAGE路过
回复

使用道具 举报

头像被屏蔽
     
发表于 2011-9-6 22:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2011-9-6 22:55 | 显示全部楼层
我.net用的少你们不要骗我,这是c#?
回复

使用道具 举报

发表于 2011-9-6 23:00 | 显示全部楼层
原来想写脚本解决的  
现在戒断中 不写了
回复

使用道具 举报

     
发表于 2011-9-6 23:04 | 显示全部楼层
看完之后感觉还是老老实实地玩HV好了
回复

使用道具 举报

     
发表于 2011-9-6 23:15 | 显示全部楼层
引用第5楼vuder于2011-09-06 22:53发表的  :
有E-H下载器在么,不用额外再弄一个了吧
回复

使用道具 举报

发表于 2011-9-7 00:33 | 显示全部楼层
以前我写过eh的下载器,自己用的时候发现这网站有流量限制的.....还不如自己想办法弄积分
回复

使用道具 举报

发表于 2011-9-7 01:26 | 显示全部楼层
引用第10楼有馬たくや于2011-09-07 00:33发表的  :
以前我写过eh的下载器,自己用的时候发现这网站有流量限制的.....还不如自己想办法弄积分
对  
还是玩那个游戏最好
买HP实在  
当然 游戏自动化
也是个很好的选择
回复

使用道具 举报

     
发表于 2011-9-7 07:51 | 显示全部楼层
有好心人给个HV的全称么
回复

使用道具 举报

头像被屏蔽
发表于 2011-9-7 09:36 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

头像被屏蔽
     
发表于 2011-9-7 09:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2011-9-7 10:57 | 显示全部楼层
话说那个Hentai@Home到底实不实用……
回复

使用道具 举报

     
发表于 2011-9-7 11:29 | 显示全部楼层
易很太下载器经常无法下载,中途也会出现下不完整等情况
回复

使用道具 举报

发表于 2011-9-7 11:46 | 显示全部楼层
引用第15楼鸡蛋灌饼于2011-09-07 10:57发表的  :
话说那个Hentai@Home到底实不实用……
有上传速度要求的
直接就没戏了
只剩下那游戏
回复

使用道具 举报

发表于 2011-9-7 11:58 | 显示全部楼层
同样的功能,写个脚本不断request然后取data不就得了。

搞浏览器点击太笨了。

伪码:
下载线程体(image_url):
        request(image_url)
        data=response.data//取返回体
         f=open(file)
         f.write(data)//存文件
爬虫体(url):
        request(page_url)
        dom=response.data//取dom
        dom=xpath.parse(dom)//用xpath解析(怎么使和语言有关)
        imgNodes=dom.select('//img')//取img节点(xpath语句怎么写看xpath的文档)
        for imgNodes in imgNodes:
              启动下载线程(imgNodes.value)
        linkNodes=dom.select('//a')//找下一页上一页节点(xpath语句具体怎么写看页面)
        for linkNode in linkNodes:
              爬虫(linkNode.value)

这比楼主的那个好使的多。
楼主的解决方案……不吐槽……不吐槽……我不能吐槽……
回复

使用道具 举报

发表于 2011-9-7 12:00 | 显示全部楼层
同样的功能,写个脚本不断request然后取data不就得了。

搞浏览器点击太笨了。

伪码:
下载线程体(image_url):
        request(image_url)
        data=response.data//取返回体
         f=open(file)
         f.write(data)//存文件
爬虫体(url):
        request(page_url)
        dom=response.data//取dom
        dom=xpath.parse(dom)//用xpath解析(怎么使和语言有关)
        imgNodes=dom.select('//img')//取img节点(xpath语句怎么写看xpath的文档)
        for imgNodes in imgNodes:
              启动下载线程(imgNodes.value)
        linkNodes=dom.select('//a')//找下一页上一页节点(xpath语句具体怎么写看页面)
        for linkNode in linkNodes:
              爬虫(linkNode.value)

这比楼主的那个好使的多。
楼主的解决方案……不吐槽……不吐槽……我不能吐槽……
回复

使用道具 举报

     
 楼主| 发表于 2011-9-7 12:24 | 显示全部楼层
引用第19楼花剑酒于2011-09-07 12:00发表的  :
同样的功能,写个脚本不断request然后取data不就得了。

搞浏览器点击太笨了。

伪码:
.......

IE automation的好处是完全模拟手工操作,理论上没有任何的footprint,如果蛋疼再加个随机delay的话。从这个层面上说,爬虫
回复

使用道具 举报

发表于 2011-9-7 12:37 | 显示全部楼层
爬虫也可以模拟浏览器,改改header就行了,随机delay也很容易。

不过感觉是在干坏事。我的纱布爬虫不但自曝家门,还在别人的那里留下“如有打扰,请联系xxx@xxx.com”之类的蛋疼信息
回复

使用道具 举报

     
 楼主| 发表于 2011-9-7 12:41 | 显示全部楼层
引用第21楼Rude于2011-09-07 12:37发表的  :
爬虫也可以模拟浏览器,改改header就行了,随机delay也很容易。

不过感觉是在干坏事。我的纱布爬虫不但自曝家门,还在别人的那里留下“如有打扰,请联系xxx@xxx.com”之类的蛋疼信息

嘛,IE automation的好,谁用谁知道
回复

使用道具 举报

     
发表于 2011-9-7 12:49 | 显示全部楼层
复制 粘贴另存为.java
回复

使用道具 举报

发表于 2011-9-7 12:51 | 显示全部楼层
EH批量容易RP
回复

使用道具 举报

     
 楼主| 发表于 2011-9-7 13:27 | 显示全部楼层
引用第23楼badmouse于2011-09-07 12:49发表的  :
复制 粘贴另存为.java

这真的是c#
回复

使用道具 举报

头像被屏蔽
     
发表于 2011-9-7 13:47 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

     
发表于 2011-9-7 15:12 | 显示全部楼层
IF 我是软妹, THEN 一定能很快学会编程
回复

使用道具 举报

     
发表于 2011-9-7 17:12 | 显示全部楼层
这东西不如写教程教别人玩HV,注册后玩个把星期,每天十分钟就有上万C了。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|Stage1st ( 沪ICP备13020230号-1|沪公网安备 31010702007642号 )

GMT+8, 2025-9-15 21:55 , Processed in 0.199333 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表