• 找到网页的某一区域,截图,并保存 HTML to Image


    static void Main(string[] args)
            {
                var url = "http://192.168.20.58/gfwd/comments-1.html";
                using (var driver = new PhantomJSDriver(@"E:seleniumphantomjs-2.1.1-windowsin"))
                {
                    //进入百度首页
                    driver.Navigate().GoToUrl(url);
                    driver.Manage().Window.Size = new Size(1280, 800);
    
                    //设置窗体最大化
                    //driver.Manage().Window.Maximize();
                    //找到对象
                    var imgelement = driver.FindElementById("screen");
                    var location = imgelement.Location;
                    var size = imgelement.Size;
    
                    var savepath = Environment.CurrentDirectory + "\codingpy_1.png";
                    driver.GetScreenshot().SaveAsFile(savepath, ScreenshotImageFormat.Png);//屏幕截图   
                    Image image = System.Drawing.Image.FromFile(savepath);
                    int left = location.X;
                    int top = location.Y;
                    int right = left + size.Width;
                    int bottom = top + size.Height;
                    //截图
                    Bitmap bitmap = new Bitmap(savepath);//原图
                    Bitmap destBitmap = new Bitmap(size.Width, size.Height);//目标图
                    Rectangle destRect = new Rectangle(0, 0, size.Width, size.Height);//矩形容器
                    Rectangle srcRect = new Rectangle(left, top, size.Width, size.Height);
                    Graphics graphics = Graphics.FromImage(destBitmap);
                    graphics.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel);
                    destBitmap.Save("d:\aa.Png");
                    graphics.Dispose();
                }
            }
    

      

  • 相关阅读:
    vim技巧2
    vim技巧1
    网站压力测试工具
    CentOS mysql安装
    破解root
    渐进式性能监测案例
    网络监测介绍
    I/O检测介绍
    虚拟内存介绍
    @Slf4j
  • 原文地址:https://www.cnblogs.com/mr-hu2009/p/Selenium.html
Copyright © 2020-2023  润新知