Sign in to follow this  
Followers 0
char101

Capture webpage using Opera and FastStone Capture

4 posts in this topic

Hi,

Since I cannot post in example scripts forum, I will share my script here. This script captures webpage in Opera browser using FastStone Capture. It can be installed to opera menu so you can capture webpages in opera by e.g. context menu.

Usage: opera-capture [-scrolling|-window|-rectangle]

-scrolling : capture full length webpage by scrolling the window

-window : capture visible window

-rectangle : capture rectangle area

; Capture webpage opened in Opera using FastStone Capture

Opt("WinTitleMatchMode", 2); match any substring

Dim $title = "Opera"
Dim $captureTitle
Dim $captureCmd
Dim $command

If $CmdLine[0] == 0 Then
    $command = "-scrolling"
Else
    $command = $CmdLine[1]
EndIf

Switch $command
Case "-scrolling"
    $captureTitle = "Capture Scrolling Window"
    $captureCmd = "^!{PRINTSCREEN}"
Case "-window"
    $captureTitle = "Capture Windows"
    $captureCmd = "!{PRINTSCREEN}"
Case "-rectangle"
    $captureTitle = "Capture Rectangle"
    $captureCmd = "^{PRINTSCREEN}"
Case Else
    MsgBox(0, "Warning", "Invalid parameter given" & @CR & "Usage: opera-capture [-scrolling|-window|-rectangle]")
    Exit
EndSwitch

Func CleanFilename($name)
    Dim $repl[9] = ['\', '/', ':', '*', '?', '"', '<', '>', '|']
    For $i = 0 To 8
        $name = StringReplace($name, $repl[$i], '_')
    Next
    Return $name
EndFunc

Func URLToFilename($url)
    Dim $matches
; taken from http://blog.stevenlevithan.com/archives/parseuri
; ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"]
    $matches = StringRegExp($url, "^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)", 2)
    If @error > 0 Then
        MsgBox(0, "Error", "Error")
        Return ""
    Else
        Dim $filename = $matches[6]
        If $matches[8] And $matches[8] <> '/' Then
            $filename = $filename & $matches[8]
        EndIf
        Return CleanFilename($filename) & ".png"
    EndIf
EndFunc

; activate Opera window
WinActivate($title)

; go to top of page
If $command = "-scrolling" Then
    Send("{HOME}")
EndIf

; save the URL
Send("{F8}")
Send("^c")
Dim $url
$url = ClipGet()

; put mouse in the middle 
Dim $pos
$pos = WinGetPos($title)
Dim $x, $y
$x = $pos[0] + Round($pos[2]/2)
$y = $pos[1] + Round($pos[3]/2)
MouseMove($x, $y, 0)

; activate print screen
Send($captureCmd)
WinWaitActive($captureTitle)
; select the window
If $command <> "-rectangle" Then
    MouseClick("left")
EndIf
; hide the mouse
If $command = "-scrolling" Then
    MouseMove(@DesktopWidth, @DesktopHeight, 0)
EndIf
; wait till capture finished
WinWaitActive("FastStone Editor")
; save
Send("^s")
WinWaitActive("Save As")
Dim $filename
$filename = URLToFilename($url)
ClipPut($filename)
; send the cleaned filename
Send("^v")

Share this post


Link to post
Share on other sites



Fixing some typos

; Capture webpage opened in Opera using FastStone Capture

Opt("WinTitleMatchMode", 2); match any substring

Dim $title = "Opera"
Dim $captureTitle
Dim $captureCmd
Dim $command

If $CmdLine[0] == 0 Then
    $command = "-scrolling"
Else
    $command = $CmdLine[1]
EndIf

Switch $command
Case "-scrolling"
    $captureTitle = "Capture Scrolling Window"
    $captureCmd = "^!{PRINTSCREEN}"
Case "-scrollingncrop"
    $captureTitle = "Capture Scrolling Window"
    $captureCmd = "^!{PRINTSCREEN}"
Case "-window"
    $captureTitle = "Capture Windows"
    $captureCmd = "!{PRINTSCREEN}"
Case "-rectangle"
    $captureTitle = "Capture Rectangle"
    $captureCmd = "^{PRINTSCREEN}"
Case Else
    MsgBox(0, "Warning", "Invalid parameter given" & @CR & "Usage: opera-capture [-scrolling|-scrollingncrop|-window|-rectangle]")
    Exit
EndSwitch

Func CleanFilename($name)
    Dim $repl[9] = ['\', '/', ':', '*', '?', '"', '<', '>', '|']
    For $i = 0 To 8
        $name = StringReplace($name, $repl[$i], '_')
    Next
    Return $name
EndFunc

Func URLToFilename($url)
    Dim $matches
; taken from http://blog.stevenlevithan.com/archives/parseuri
; ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"]
    $matches = StringRegExp($url, "^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)", 2)
    If @error > 0 Then
        MsgBox(0, "Error", "Error")
        Return ""
    Else
        Dim $filename = $matches[6]
        If $matches[8] And $matches[8] <> '/' Then
            If StringRight($matches[8], 1) == '/' Then
                $matches[8] = StringLeft($matches[8], StringLen($matches[8]) - 1)
            EndIf
            $filename = $filename & $matches[8]
        EndIf
        Return CleanFilename($filename) & ".png"
    EndIf
EndFunc

; activate Opera window
WinActivate($title)

; put mouse in the middle 
Dim $pos
$pos = WinGetPos($title)
Dim $x, $y
$x = $pos[0] + Round($pos[2]/2)
$y = $pos[1] + Round($pos[3]/2)
MouseMove($x, $y, 0)

; go to top of page
If $command == "-scrolling" Or $command == "-scrollingncrop" Then
    MouseClick("left")
    Send("{HOME}")
EndIf

; save the URL
Send("{F8}")
Sleep(100)
Send("^c")
; too fast, and the copy will fail
Sleep(100)
Dim $url
$url = ClipGet()
MsgBox(0, "Info", "I get " & $url & " from clipboard")

; activate print screen
Send($captureCmd)
WinWaitActive($captureTitle)
; select the window
If $command <> "-rectangle" Then
    MouseClick("left")
EndIf
; hide the mouse
If $command == "-scrolling" Or $command == "-scrollingncrop" Then
    MouseMove(@DesktopWidth, @DesktopHeight, 0)
EndIf
; wait till capture finished
WinWaitActive("FastStone Editor")
; save
Dim $filename
$filename = URLToFilename($url)
MsgBox(0, "Info", "ClipPut " & $filename)
ClipPut($filename)
If $command <> "-scrollingncrop" Then
    Send("^s")
    WinWaitActive("Save As")
; send the cleaned filename
    Send("^v")
EndIf

Share this post


Link to post
Share on other sites

Pretty nifty script... Now if I only used Opera and not Firefox... ;) Well Firefox has ScrapBook which is great for saving a webpage, but not for printing.

Share this post


Link to post
Share on other sites

Pretty nifty script... Now if I only used Opera and not Firefox... ;) Well Firefox has ScrapBook which is great for saving a webpage, but not for printing.

Hey... Do we have any function in Auto it which will help to perform FastStone like work i.e. capturing Scrolling Window ??

;)

:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0