Search code examples
urlscreenshotemeditor

Visiting Multiple Links and Auto-saving Screenshots


There is something I want and I want to know if it is possible.

What I want is to visit multiple URLs and automatically save screenshots. And if possible, the save name of the screenshot should be the same as its URL.

For example, would it be possible to do this with Excel or EmEditor? Maybe with macro?

Is it possible to do this? And if possible how can I do it?

EXAMPLE:

URLS: 3 Pieces (Or More)

  1. https://stackoverflow.com/questions/one
  2. https://stackoverflow.com/questions/two
  3. https://stackoverflow.com/questions/three

Visiting these links automatically and saving screenshots as below.

Screenshots:

  1. stackoverflow.com-questions-one.jpg
  2. stackoverflow.com-questions-two.jpg
  3. stackoverflow.com-questions-three.jpg

Note: The HTTPS:// part may not be in the registration name, as : and / signs will not be accepted during registration. Also the / symbol has been replaced with a - sign.

Screenshots 2:

  1. questions-one.jpg
  2. questions-two.jpg
  3. questions-three.jpg

Note 2: Even if the entire URL is not the filename. Just like above.

I visited a similar question. However, the information presented did not do exactly what I wanted. I tried the sample codes provided. For example this code.

I opened an excel file and created a macro with VBA and ran it. When the macro ran Internet Explorer opened and became Full Screen. The page that opened was www.google.com. Then the screenshot was automatically taken and saved in the WORD document.

This is not what I want. Also; The other code in the question didn't work at all. If the above example doesn't explain exactly what I want, please see the steps below.

  1. Multiple URLs will be opened one by one automatically.

(It could be Internet Explorer & Chrome or Edge or anyone.)

  1. The screen will be enlarged and switched to full screen mode. Note: What I'm talking about at this point is the action performed with the F11 key.
  2. Wait 7 seconds for the text "Press the F11 key to exit full screen" disappears on the screen.
  3. A screenshot will be taken and pasted into Microsoft Paint.
  4. The screenshot will be saved with the URL name. Sample: Screenshots should be saved with the part of the current URL after .com. The / sign in the links will cause problems when creating the filename. Therefore, when saving the screenshot, it will be necessary to automatically replace the / with a - sign and save it as such.

IMPORTANT

I do not expect any service from you; I just don't have enough coding knowledge to do them. To be frank, I do not have any information under the name of Code Information. I respect the knowledge of each of you very much and I want you to know that I am sincere about it. I'm just someone looking for a way to do what I want.

I don't expect anything from scratch on this; I'm just waiting for someone who needs help on the same issue before to share if they have any solution on this issue.


Solution

  • First Method for Windows 7, 8.1, 10

    1. Close all windows first.

    2. Open your default web browser and maximize the browser window, and close the browser window.

    3. Press Win+R, and type SnippingTool.exe to run the Snipping Tool. click Mode button (or press Alt+M) and select Full Screen. Press Ctrl+S to show the Save As dialog box. I recommend creating a new folder (for example, Scrn), and save a screenshot in the new created folder, such as Scrn\screenshot.png. This is just a dummy screenshot, and you can delete it later. Doing this allows the following screenshots saved into this new same folder. Close the Snipping Tool.

    4. Open the text file with a list of URLs with EmEditor. Please don't maximize the EmEditor window. I would recommend testing with a few URLs first. The text file should look like this:

    https://www.emeditor.com/
    https://stackoverflow.com/
    https://www.google.com/
    
    1. Run the macro (Screenshot1.jsee) below, and please don't touch keyboard or mouse until you see Finished saving screenshots in a dialog box.

    Screenshot1.jsee

    document.selection.StartOfDocument();
    nLines = document.GetLines();
    for( y = 1; y <= nLines; ++y ) {
        str = document.GetLine( y );   // retrieve an URL at a line
        if( str.length != 0 ) {
            str = str.replace("http://", "");  // remove "http://" and "https://"
            str = str.replace("https://", "");
            if( str.charAt( str.length - 1 ) == '/' ) {  // remove the last slash character
                str = str.substr( 0, str.length - 1 );
            }
            str = str.replace("/", "-");   // replace invalid characters with "-"
            str = str.replace("~", "-");
            str += ".png";   // append ".png"
            
            document.selection.OpenLink();
            document.selection.LineDown(false,1);
            Sleep( 5000 );  // wait for the browser to become active and show the webpage completely
    
            WshShell = new ActiveXObject( "WScript.Shell" );
            WshShell.Run( "SnippingTool.exe" );
            Sleep( 2000 );  // wait for the Snipping Tools appears
            shell.SendKeys( "%M" );  // Press Alt+M
            Sleep( 100 );
            shell.SendKeys( "s" );  // Press s
            Sleep( 100 );
            shell.SendKeys( "%n" );  // Press Alt+N
            Sleep( 1000 );
            shell.SendKeys( "~" );  // Press Enter
            Sleep( 100 );
            shell.SendKeys( "~" );   // Press Enter
            Sleep( 1000 );
            shell.SendKeys( "%{F4}" );  // Press Alt+F4 to close Snipping Tools
            Sleep( 1000 );
            shell.SendKeys( "y" );   // select YES
            Sleep( 1000 );
            shell.SendKeys( str + "~" );   // enter file name
            Sleep( 1000 );
            
            shell.SendKeys( "%{F4}" );  // Press Alt+F4 to close web browser
            Sleep( 1000 );
        }
    }
    alert( "Finished saving screenshots" );
    

    To run this, save this code as, for instance, Screenshots.jsee, and then select this file from Select... in the Macros menu. Finally, select Run Screenshots.jsee in the Macros menu.

    Notes: If the same file names exist in the destination folder, the macro will stop when the Snippets Tools prompts for overwrite. Please make sure the destination folder is empty or that same file names don't exist in the destination folder.

    If something went wrong, you can cancel the macro by pressing Ctrl+Break (or ESC twice consecutively) while EmEditor has the keyboard focus.

    Second Method for Windows 10

    This method should be more robust and faster than the first method.

    1. First, press Win+PrintScrn and make sure a screenshot is saved in your personal Pictures/Screenshots folder. Delete this file, and ensure the folder is empty.

    2. Close all windows.

    3. Open your default web browser and maximize the browser window, and close the browser window.

    4. Open the text file with a list of URLs with EmEditor. Run the macro below.

    Screenshot2.jsee

    document.selection.StartOfDocument();
    nLines = document.GetLines();
    for( y = 1; y <= nLines; ++y ) {
        str = document.GetLine( y );   // retrieve an URL at a line
        if( str.length != 0 ) {
            document.selection.OpenLink();
            Sleep( 5000 );  // wait for the browser to become active and show the webpage completely
    
            shell.SendKeys( "{LWIN DOWN}{PRTSC}{LWIN UP}" );
            Sleep( 500 );
            
            shell.SendKeys( "%{F4}" );  // Press Alt+F4 to close web browser
            Sleep( 500 );
        }
        document.selection.LineDown(false,1);
    }
    alert( "Finished saving screenshots" );
    
    1. You will see screenshots saved in your personal Pictures/Screenshots folder. Note this folder path, and the first file name (and the index number). For example, if the file name is Screenshot (13).png, the index number is 13.

    2. Copy the macro below to Screenshot3.jsee, and correct the folder name (sFolder) and index number (nIndex). If you are using non-English Windows and the file name is not Screenshot (...).png, you might also need to correct the file name (sFile1). Open the same text file with URLs, and then run this macro.

    Screenshot3.jsee

    sFolder = "C:\\Users\\...\\Pictures\\Screenshots\\";  // Screenshots folder where files are saved on [Win]+[PrintScrn]. Use double-backslashes "\\".
    sFile1 = "Screenshot (";   // screenshot file name before index number
    nIndex = 13;               // index number of first screenshot, for example, 13 for Screenshot (13).png
    sFile2 = ").png";          // screenshot file name after index number
    
    fso = new ActiveXObject( "Scripting.FileSystemObject" );
    
    document.selection.StartOfDocument();
    nLines = document.GetLines();
    for( y = 1; y <= nLines; ++y ) {
        str = document.GetLine( y );   // retrieve an URL at a line
        if( str.length != 0 ) {
            str = str.replace("http://", "");  // remove "http://" and "https://"
            str = str.replace("https://", "");
            if( str.charAt( str.length - 1 ) == '/' ) {  // remove the last slash character
                str = str.substr( 0, str.length - 1 );
            }
            str = str.replace(/[/<>:\\|?*\"]/g, "-");   // replace invalid characters with "-"
            str += ".png";   // append ".png"
            
            sSrc = sFolder + sFile1 + nIndex + sFile2;
            sDest = sFolder + str;
            fso.MoveFile( sSrc, sDest );
        }
        document.selection.LineDown(false,1);
        ++nIndex;
    }
    alert( "Finished renaming screenshots" );