Parsing and precise placement of data contained in clipboard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Parsing and precise placement of data contained in clipboard

23 Jan 2019, 07:43

Hello Folks,

Say I copy something like a craigslist ad with text and a swath of pictures. To copy the content inside this craigslist web page, I select all with ctrl+a and then copy with ctrl+c.

How can I look at all these individual items contained within my clipboard? Is there some sort of a way to loop through these items with a GUI, or even simpler visualization, and/or text so that I can see and place these items somewhere else with precision?

I was thinking of ways to save time when looking around for new housing, so I'd like to paste craigslist housing ads straight into Excel using COM. My issue is that when I copy the clipboard and paste straight into Excel, the pictures all stack on top of each other and it doesn't save me any time or serve any use. I beleive I can figure out the Excel COM part myself - just need help understanding how the clipboard works with data.

I could see this benefiting myself in other scenarios. But since I don't understand how this works, I'm stuck.

Any help is apprceciated! Thank you for your insightful replies in advance!!
-TL
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 02:20

Hello,

Does anyone know more about this?

Best,
-TL
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 03:00

looks impossible
you have to express what you want to do with lines of codes
if you could not make it like this
forget about it
OR
you needed AI, DeepLearing something that kinds..
OR
just download all the web page, there should be bunch of files
and parse file(s) you wanted
but, again, you could needed Ai, DL...
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 06:40

IMEime wrote:
28 Jan 2019, 03:00
looks impossible
you have to express what you want to do with lines of codes
if you could not make it like this
forget about it
OR
you needed AI, DeepLearing something that kinds..
OR
just download all the web page, there should be bunch of files
and parse file(s) you wanted
but, again, you could needed Ai, DL...
Definitely is not impossible. This is not a Deep Learning / AI situation either.

When you highlight something on a webpage and press CTRL+C to copy it into your clipboard, all that clipboard data gets stored somewhere in a structured way.

Afterwards, when you press CTRL+V, it pastes the clipboard contents in an ordered pattern. For instance, if you copy and paste the post I have posted here, the words "Definitely is not possible" will be pasted before "Afterwards, when you press CTRL+V..."

So when I copy a small page full of images and bodies of text, it gets stored somewhere in a structured pattern that can be accessed somehow. I just don't know where or how to access this stored (and structured) data so that I can see how the data is linearly stored (and be able to manipulate it).

I'm pretty new to programming, but this must be possible.
-TL
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 06:44

you are just talking or thinking
talking or thinking is good
but, in this case they're nothing

my point is very simple
where is your code ?
treestyle
Posts: 11
Joined: 10 Jan 2019, 22:32

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 12:30

Tigerlily wrote:
28 Jan 2019, 06:40
IMEime wrote:
28 Jan 2019, 03:00
looks impossible
you have to express what you want to do with lines of codes
if you could not make it like this
forget about it
OR
you needed AI, DeepLearing something that kinds..
OR
just download all the web page, there should be bunch of files
and parse file(s) you wanted
but, again, you could needed Ai, DL...
Definitely is not impossible. This is not a Deep Learning / AI situation either.

When you highlight something on a webpage and press CTRL+C to copy it into your clipboard, all that clipboard data gets stored somewhere in a structured way.

Afterwards, when you press CTRL+V, it pastes the clipboard contents in an ordered pattern. For instance, if you copy and paste the post I have posted here, the words "Definitely is not possible" will be pasted before "Afterwards, when you press CTRL+V..."

So when I copy a small page full of images and bodies of text, it gets stored somewhere in a structured pattern that can be accessed somehow. I just don't know where or how to access this stored (and structured) data so that I can see how the data is linearly stored (and be able to manipulate it).

I'm pretty new to programming, but this must be possible.

You probably want another programming language that will download and parse the HTML file and let you copy the parts you need. Try asking in a Perl forum, and perhaps they'll give you a complete solution. Tell them you're totally new to programming and were sent over from AutoHotKey, a hot key / macro recorder for Windows :).

You will not be able to understand what they're doing, without programming background, but perhaps they'll help you out enough to get what you need done.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Parsing and precise placement of data contained in clipboard

28 Jan 2019, 23:17

Tigerlily wrote:
23 Jan 2019, 07:43
Hello Folks,

Say I copy something like a craigslist ad with text and a swath of pictures. To copy the content inside this craigslist web page, I select all with ctrl+a and then copy with ctrl+c.

How can I look at all these individual items contained within my clipboard? Is there some sort of a way to loop through these items with a GUI, or even simpler visualization, and/or text so that I can see and place these items somewhere else with precision?

I was thinking of ways to save time when looking around for new housing, so I'd like to paste craigslist housing ads straight into Excel using COM. My issue is that when I copy the clipboard and paste straight into Excel, the pictures all stack on top of each other and it doesn't save me any time or serve any use. I beleive I can figure out the Excel COM part myself - just need help understanding how the clipboard works with data.

I could see this benefiting myself in other scenarios. But since I don't understand how this works, I'm stuck.

Any help is apprceciated! Thank you for your insightful replies in advance!!
Tigerlily, there is a difference between needing help with a script (and posting something that you have worked on or at least found somewhere that does part of what you want) and asking or demanding other people make you a script. The experienced programmers can easily spot the difference in intention, especially when the person has posted no semblance of a script.

In addition, a person can be asking for something that is very involved and contains a complicated sequences of steps. Thus it becomes more than just merely a help question, it becomes a project, that will take a lot of time to complete. This then gets into the scenario of a back and forth, where the programmer trying to help is making scripts that the requester doesn't feel is satisfactory or will be constantly changing requirements. Imagine being the unpaid volunteer programmer having to spend hours trying to please someone that is arguably being "lazy" (for lack of a better term). Remember that helping here is voluntary, and many programmers do it out of compassion, pure love of programming (as it's their hobby), or sense of wanting to contribute back to the community because the AutoHotkey program or the forum has helped them in the past.

If you don't what to do the hard studying, and want something made for you without you showing any effort or code, it's arguably best that you hire a programmer. There are many websites where you can do this, and some will do for cheap. To include you can message and ask various Autohotkey programmers here, or choose one of those other websites. In this way, you are more likely to get a programmer to take on your project with numerous steps. Lastly, remember that the programmers on the AutoHotkey forum are volunteers, and are not obligated or under contract to do anything.

With that typed, your first step, if you choose to go the hard way and study, is to go here https://autohotkey.com/docs/misc/Clipboard.htm And study on using loop parse for the clipboard. Put together some code and post it, then people (volunteers) are more likely to help. If you choose not to do such, you do have the choice of going down the path of hiring someone.

Peace
User avatar
Tigerlily
Posts: 377
Joined: 04 Oct 2018, 22:31

Re: Parsing and precise placement of data contained in clipboard

29 Jan 2019, 06:21

SOTE wrote:
28 Jan 2019, 23:17
Hi SOTE,

Thank you for your thoughtful reply.

I didn't post any code because I felt I needed understanding of how AHK interacts with the clipboard. I've already read that clipboard documentation up and down without coming up with a solution.

I did not make any demands in this Ask for Help forum post for anyone to make me a script, just simply asked for help as I'm stuck. Did it seem like that was my intent? I've only been programming for a few months, but if you look, I've already spent some time contributing back to the community by trying to come up with solutions to other AHK user's posts in the Ask for Help forum. I don't think that is lazy, as I am spending my free time trying to help others who have asked for help since they don't understand how to reach their solution. If it wasn't for all the awesome people on the AHK forum, I'd still probably be sending keystrokes and mouseclicks in a flawed attempt to automate Excel.

I don't believe that I asked anyone for a ludicrous and complex script with a complicated sequence of steps that required an everchanging list of requirements and back and forth communication?? Please show me what in my OP alludes to that, as that is way off from my intent. I think if you re-read it, you will see that my OP required no code needed to get a reasonable answer. I was actually hoping for an answer that was conceptual and possibly contained resources to where I could do more studying on this. Before posting this thread, I spent over 5 hours trying several methods to acheive my goal with every attempt ending in failure. I'm always looking to create my own solution without others help if I am able - so the only time I post on here to ask for help is after many hours of failure.
treestyle wrote:
28 Jan 2019, 12:30
Thanks for a constructive response treestyle. I had considered this, but thought that AHK would likely have the capabilities to do such an operation. If I can't find a solution using solely AHK, I will probably go this route. I'm developing an Excel utility that helps speed up research and marketing tasks. My goal would be to have no dependencies on other programs though if possible.
IMEime wrote:
28 Jan 2019, 06:44
you are just talking or thinking
talking or thinking is good
but, in this case they're nothing

my point is very simple
where is your code ?
Hi IMEime, here are some of the various codes I have tried to acheive my goal:

Code: Select all

#SingleInstance, force
SendMode, Input


Run, https://slo.craigslist.org/apa/d/san-luis-obispo-bright-clean-1bedroom/6806473153.html

!1::		;		No images will copy over when I do it like this, I see that AHK stores the images in some sort of binary format, but not sure how to convert or keep the images when pasting over 
Send, ^a		
Clipboard = 
Send, ^c 
ClipWait, 25
FileAppend, %ClipboardAll%, C:\Excel Backups\cliptest.csv	;	I've tried saving it as other formats such as .xlsx, .txt, .jpg, etc - I know that CSV formats will not hold images, but moving the data in this way lays out the data in a somewhat more orderly way
return

!2::		;		This reliably copies everything over into Excel, but the images are converted in binary format and I don't know how to covert them back or interact with them in their non-converted form
Send, ^a		;		
Clipboard = 
Send, ^c 
ClipWait, 25
Loop, parse, clipboard, `n, `r
{
	Xl := ComObjActive("Excel.Application") 
    Xl.Range("A" A_Index) := A_LoopField
}
return

!3::		;		This quickly and reliably copies everything over into Excel, but the images are stacked on top of each other and I don't know how to place them where I want
Send, ^a
Clipboard = 
Send, ^c 
ClipWait, 25
Xl := ComObjActive("Excel.Application") 
Xl.Selection.PasteSpecial() 
return
The ALT+3 hotkey option seems to be the closest I can get. The issue is that I still don't know how to interact with or identify the images. I know that I could use Excel COM to identify each newly added images name (such as "PIcture1"), then try to use other COM requests to position each image in different cells after identifying each picture. I just feel like there is an easier way and I would be over comlicating things by going down this route.

Thanks for the replies, any help is greatly appreciated.
-TL
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Parsing and precise placement of data contained in clipboard

31 Jan 2019, 10:34

- I would consider the Excel 'get objects and reposition them' approach that you mentioned.
- If you were thinking about parsing the html to get information. In Internet Explorer to get the html from a webpage:

Code: Select all

;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;internet explorer - get html
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
;Clipboard := oWB.document.documentElement.innerHTML
Clipboard := oWB.document.documentElement.outerHTML
oWB := ""
return
- Here is some code to get the html from the clipboard. This should work regardless of which browser put the html onto the clipboard.

Code: Select all

Clipboard := JEE_ClipboardGetHtml()
return

JEE_ClipboardGetHtml(vEnc:="CP0")
{
	local
	vFormat := DllCall("user32\RegisterClipboardFormat", "Str","HTML Format", "UInt")
	return JEE_ClipboardGetText(vFormat, vEnc)
}

JEE_ClipboardGetText(vFormat:=0xD, vEnc:="")
{
	local
	;CF_LOCALE := 0x10 ;CF_UNICODETEXT := 0xD
	;CF_OEMTEXT := 0x7 ;CF_TEXT := 0x1
	if !DllCall("user32\IsClipboardFormatAvailable", "UInt",vFormat)
		return
	if !DllCall("user32\OpenClipboard", "Ptr",0)
		return
	if !hBuf := DllCall("user32\GetClipboardData", "UInt",vFormat, "Ptr")
	{
		DllCall("user32\CloseClipboard")
		return
	}

	pBuf := DllCall("kernel32\GlobalLock", "Ptr",hBuf, "Ptr")
	vSize := DllCall("kernel32\GlobalSize", "Ptr",hBuf, "UPtr")
	VarSetCapacity(vOutput, vSize, 0)
	DllCall("msvcrt\memcpy", "Ptr",&vOutput, "Ptr",pBuf, "UPtr",vSize, "Cdecl Int")
	if !(vEnc = "")
		vOutput := StrGet(&vOutput, vSize, vEnc)
	VarSetCapacity(vOutput, -1)

	DllCall("kernel32\GlobalUnlock", "Ptr",hBuf)
	DllCall("user32\CloseClipboard")
	return vOutput
}
- I thought your question was pretty reasonable, of the form: 'this may be a big challenge, but I'm looking for tips, or possibly more if it's easy enough or if code has already been written for it'. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: tabr3 and 243 guests