Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Copy/Paste from web page


  • Please log in to reply
8 replies to this topic

#1 b0x4it

b0x4it

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 21 April 2012 - 02:10 PM

Suppose you select part of a web page that includes images and texts and copy it into the clipboad by Ctrl+C; pasting it into a compose windows of Thunderbird results in having all images and texts together in thunderbird where the images are loaded from somewhere in the web.

I'd like to simulate this process using Autoit using the following code, but it just shows the text and not the images in the compose windows of Thunderbird. I am wondering if there is anyway to simulate the exact operation of manually doing this task by Ctrl+C and then Ctrl+V?

Send("^c") Sleep(200) $Clipboard = ClipGet() Sleep(200) $Clipboard="-compose " & '"' & "body=" & "'" & $Clipboard & "'" & '"' Run("c:\Program Files\Mozilla Thunderbird\thunderbird.exe " & $Clipboard , "", "")


Thanks in advance







#2 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,067 posts

Posted 21 April 2012 - 02:53 PM

Clipget returns the text content of the clipboard, whereas you want the html content.

To do this you will need to use the _Clipboard_* library functions with CF_HTML format (note that CF_HTML is not a constant, you have to use RegisterClipboardFormat first).

Local $CF_HTML = _ClipBoard_RegisterFormat("HTML Format") ; Gets the HTML format identifier MsgBox(0, "test", _ClipBoard_GetData($CF_HTML))


Unfortunately I can't test at the moment, but IIRC there is a header (i.e. you don't just get the HTML, you get some meta information). You may need to parse this before sending the html to thunderbird. Also be careful of newlines and quotes in the html... These can cause all sorts of problems with the run command.

#3 b0x4it

b0x4it

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 23 April 2012 - 01:49 PM

many thanks for your reply, but I coudn't make it working! I google the functions, but couldn't find any sample. would you please give me more description?

the function just returs lots of numbers! I also tried the code in this topic, but with no luck!:
http://www.autoitscript.com/forum/topic/79169-clipboard-data-in-html-format/

btw, sorry for the late reply. I haven't received any notification regarding a reply.
thanks

#4 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,067 posts

Posted 23 April 2012 - 04:03 PM

_Clipboard_GetData returns binary I think... Still can't test, but try `BinaryToString(_ClipBoard_GetData($CF_HTML))` and see if that turns the numbers you were getting to text.

#5 b0x4it

b0x4it

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 24 April 2012 - 02:02 PM

thanks for the reply.
It works but it is similar to Clipget() and just carries the text and not the images.
any solution?
thanks

#6 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,067 posts

Posted 24 April 2012 - 03:56 PM

Meh. Did some testing and ended up going the long way round:

AutoIt         
#include <ClipBoard.au3> If (Not _ClipBoard_Open(0)) Then     ConsoleWriteError("_ClipBoard_Open failed" & @LF) Else     Local $sData = _Clipboard_GetHTML()     Switch @error         Case 1             ConsoleWriteError("Could not register CF_HTML format" & @LF)         Case 2             ConsoleWriteError("Clipboard data not available in HTML format" & @LF)         Case 3             ConsoleWriteError("Invalid HTML format header (missing end or start fragment)" & @LF)         Case 0             ConsoleWrite($sData & @LF)     EndSwitch EndIf _ClipBoard_Close() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Clipboard_GetHTML ; Description ...: Retrieves the data from the clipboard in HTML format ; Syntax ........: _Clipboard_GetHTML( ) ; Parameters ....: None ; Return values .: Success: Returns the data from the clipbard as html. ;                  Failure: Returns an empty string and sets @error: ;                           | 1 - Could not register CF_HTML format ;                           | 2 - Clipboard data not available in HTML format ;                           | 3 - Invalid HTML format header (missing end or start fragment) ; Author ........: Matt Diesel (Mat) ; Modified ......: ; Remarks .......: This assumes that the clipboard is already open. The _Clipboard_Open function should be called first. ; Related .......: ; Link ..........: ; Example .......: Above. ; =============================================================================================================================== Func _Clipboard_GetHTML()     Local $CF_HTML, $pHTML, $tHeader, $asHeader, $asLine, $iStartFragment = -1, $iEndFragment = -1     ; Register the CF_HTML format     $CF_HTML = _ClipBoard_RegisterFormat("HTML Format")     If (Not $CF_HTML) Then Return SetError(1, 0, "") ; Could not register CF_HTML format     If (Not _ClipBoard_IsFormatAvailable($CF_HTML)) Then Return SetError(2, 0, "") ; Clipboard data not available in HTML format     $pHTML = _ClipBoard_GetDataEx($CF_HTML)     $tHeader = DllStructCreate("char t[104]", $pHTML)     $asHeader = StringSplit(DllStructGetData($tHeader, "t"), @CRLF, 1)     ; Find start and end of fragment from header.     For $i = 1 To $asHeader[0]         $asLine = StringSplit($asHeader[$i], ":")         Switch $asLine[1]             Case "StartFragment"                 $iStartFragment = Int($asLine[2])             Case "EndFragment"                 $iEndFragment = Int($asLine[2])         EndSwitch     Next     If (($iEndFragment < 0) Or ($iStartFragment < 0)) Then Return SetError(3, 0, "") ; Invalid HTML format header (missing end or start fragment)     $tHeader = DllStructCreate("char t[" & $iEndFragment - $iStartFragment + 1 & "]", $pHTML + $iStartFragment)     Return DllStructGetData($tHeader, "t") EndFunc   ;==>_Clipboard_GetHTML


Good news for you is that you just need to copy _Clipboard_GetHTML and use it. How that deals with images I'm not sure, and it is almost certainly browser dependant.

#7 b0x4it

b0x4it

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 25 April 2012 - 08:34 AM

wwooww! so long code!

thank you very much.
it partially works. I mean if I just select an image in a web page, it copy/paste the image, but it will also paste a "<" character after the image.
I also tried it with a bit more complicated page like google search, but it just paste a dot instead of all copied items in cliboard.
it should be noted that I am passing $sData to Thunderbird using the following code:

$Clipboard="-compose " & '"' & "body=" & $sData & '"' msgbox(0,"","c:Program FilesMozilla Thunderbirdthunderbird.exe " & $Clipboard)


I reckon here is the problem and not your code as it changes the $sData to text and passes it to thunderbird! I am wondering if you have other way of passing the html data from $sData to the body part of Thunderbird compose windows?
Thanks

#8 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,067 posts

Posted 25 April 2012 - 08:45 AM

A single character? I think I know what that could be... Try changing the second last line of the function, in particular remove the +1 I added out of habbit.

"char t[" & $iEndFragment - $iStartFragment + 1 & "]"


Should probably be:

"char t[" & $iEndFragment - $iStartFragment & "]"


You shouldn't have to add one because there is no terminating null anyway, and we are only reading. ;)

#9 b0x4it

b0x4it

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 30 April 2012 - 02:01 AM

thanks for your reply, and sorry again for my late replay!
I have requested a reply notofication for this topic, but I never received any notification for the replies!! and I have to check this page to see if there is any reply!

anyway, as I explained in my pre, the main problem is that I am passing $sData to Thunderbird using the following code:

$Clipboard="-compose " & '"' & "body=" & $sData & '"' msgbox(0,"","c:Program FilesMozilla Thunderbirdthunderbird.exe " & $Clipboard)


as it changes the $sData to text and passes it to thunderbird! I am wondering if you have other way of passing the html data from $sData to the body part of Thunderbird compose windows?
Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users