Page 2 of 2

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 10:30 am
by jak64
Hello Allen,
I tested the code but in the debug, I get the copy of the program code!

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 11:26 am
by BarryG
What's the URL for musical bases, so I can test?

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 11:54 am
by jak64
Hello BarryG

I looked at this site but I don't know how to use it

https://musicbrainz.org/

I also looked in this list but did not find any database that I could exploit

https://en.wikipedia.org/wiki/List_of_o ... _databases

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 1:54 pm
by Allen
@Jak64,
Hello Allen,
I tested the code but in the debug, I get the copy of the program code!
Please change

Code: Select all

WebPage2Clipboard()
to

Code: Select all

WebPage2Clipboard():Delay(3000)
and try again.

Thanks

Allen

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 2:03 pm
by jak64
Hi Allen
Here's the program I'm testing and it doesn't work.

Code: Select all

Procedure WebPage2Clipboard()
  Protected.INPUT InputKey
  ; Control key Down
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;a press
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 65
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ; a release
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 65
  InputKey\ki\dwFlags =  #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;c press
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 67
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;c release
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 67
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)

  ;Control key up
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
EndProcedure

#debut_url="https://www.google.com/search?q="
#fin_url=""
Chanson$="date chanson Michael Jackson Thriller"
RequeteGoogle$=URLEncoder(#debut_url + Chanson$ + #fin_url  )

RunProgram("C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
Delay(4000); wait till chrome becomes stable
;OriginalClipBoard$=GetClipboardText()
WebPage2Clipboard():Delay(3000)
A$=GetClipboardText()
Debug a$
;SetClipboardText(OriginalClipBoard$)

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 2:51 pm
by Allen
@Jak64,

One reason I can think of is the delay time is not enough and the web page is not completly loaded. Please take a look at below video. You should be able to see the CTRL-A, CTRL-C effect on the chrome page.

https://streamable.com/5b8k7g

Please change the delay time at line 48 to delay(20000) and line 50 to delay(10000) and try again.

Thanks.

Allen Wong

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 5:29 pm
by Caronte3D
Change:
RunProgram("C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
by
RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 5:58 pm
by jak64
Hello Allen and Caronte3D,

I removed all the delays and changed the line

RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",GoogleRequest$,"")

As Caront3D advised me and it works perfectly.

On the other hand, if I run the program 10 times, it opens 10 web pages. How to close them programmatically?

THANKS

Here is the code that works

Code: Select all

Procedure WebPage2Clipboard()
  Protected.INPUT InputKey
  ; Control key Down
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;a press
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 65
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ; a release
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 65
  InputKey\ki\dwFlags =  #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;c press
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 67
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;c release
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 67
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)

  ;Control key up
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
EndProcedure

#debut_url="https://www.google.com/search?q="
#fin_url=""
Chanson$="date chanson Michael Jackson Thriller"
RequeteGoogle$=URLEncoder(#debut_url + Chanson$ + #fin_url  )

RunProgram("C:\Program Files\Google\Chrome\Application\chrome_proxy.exe",RequeteGoogle$,"")
WebPage2Clipboard();:Delay(2000)
A$=GetClipboardText()
Debug a$

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 6:06 pm
by Caronte3D
Really the best advice is BarryG's You should use a music database through her API.
Maybe you need to investigate more how to access it, but that way is far better than the google scraper one

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 6:21 pm
by jak64
Hello caronte3D,
I agree with you but I want to do this just once to update the release date in my database which has 5000 MP3 songs and empty tags.

For new songs, I will read the tags after ripping the CD to mp3.

Re: Simulate CTRL+A and CTRL+C

Posted: Sun Apr 09, 2023 6:24 pm
by ZX80
Hello, jak64.

To be honest, it's all crutches. And it's not safe! I agree with Caronte3D and BarryG.
But... If you insist on this option, then I would do this:

Code: Select all

Program = RunProgram(...)
ProcessID = ProgramID(Program)
then you can list all running processes in the system and kill the one you need. There have already been such examples on this forum somewhere. Try searching.

Re: Simulate CTRL+A and CTRL+C

Posted: Mon Apr 10, 2023 12:15 am
by vwidmer
This works for me:

Code: Select all

Procedure ExtractRegExMatch (text$, Array result$(1), regex$ = "")
  Static iRegEx
  Protected iRetVal = -1 ; regex error
  
  If regex$
    If iRegEx > 0:FreeRegularExpression(iRegEx):EndIf     
    iRegEx = CreateRegularExpression(#PB_Any, regex$)
  EndIf
  
  If iRegEx
    iRetVal = ExtractRegularExpression(iRegEx, text$, result$())   
  EndIf
  
  ProcedureReturn iRetVal
EndProcedure

Procedure.s ExtractRegExString(text$, regex$ = "")
  Dim result$(0)
  ExtractRegExMatch (text$, result$(), regex$)
  ProcedureReturn result$(0)
EndProcedure

Procedure.s scrapString(String$,StartString$,EndString$)
  stS.i = FindString(String$,StartString$)
  stE.i = FindString(String$,EndString$,stS)
  If stS = 0 And stE = Len(EndString$):stE = 0:EndIf
  ProcedureReturn Mid(String$,stS,stE)
EndProcedure

Procedure.s GetURLText(url$)
  *Buffer = ReceiveHTTPMemory(URLEncoder(url$))
  If *Buffer
    Size = MemorySize(*Buffer)
    text$ = PeekS(*Buffer, Size, #PB_UTF8 | #PB_ByteLength)
    FreeMemory(*Buffer)
  EndIf
  ProcedureReturn text$
EndProcedure

Debug ExtractRegExString(scrapString(GetURLText("https://www.google.com/search?q=Lionel Richie Can't get over you release date"),"Released","img"),"(?!>)[0-9]{1,4}(?=</)")

Re: Simulate CTRL+A and CTRL+C

Posted: Mon Apr 10, 2023 1:17 am
by Allen
@Jak64,
On the other hand, if I run the program 10 times, it opens 10 web pages. How to close them programmatically?
You can send another short cut key sequence to the chrome window to close it.

Code: Select all

Procedure CloseChromeTap()
  Protected.INPUT InputKey
  ; Control key Down
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;w press
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 87 ;87
  InputKey\ki\dwFlags = 0
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;w release
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = 87 ;87
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
  ;Control key up
  InputKey\Type = #INPUT_KEYBOARD
  InputKey\ki\wVk = #VK_CONTROL
  InputKey\ki\dwFlags = #KEYEVENTF_KEYUP
  SendInput_(1, @InputKey, SizeOf(INPUT))
  Delay(20)
EndProcedure
Close the tap after you got the clipboard content.

Code: Select all

A$=GetClipboardText()
CloseChromeTap()
Thanks.

Allen

Re: Simulate CTRL+A and CTRL+C

Posted: Mon Apr 10, 2023 10:47 am
by jak64
Thank you Allen

Re: Simulate CTRL+A and CTRL+C

Posted: Mon Apr 10, 2023 5:07 pm
by Marc56us
If you send 5000 identical requests from the same IP to the same server, the firewall of the remote site will consider it a flooding attempt and will block you (at least for a while).
If you want to update a large number of titles, you will have to use a remote database (and sometimes get a login, sometimes pay).
Otherwise, you have to do it one by one. Some sites allow free access with a certain limit per day (e.g. 200 queries / day).
As for the analysis of a standard page of google or other, as you can see, it changes every day.
So you can easily build something based on RegEx, but it will have to be modified often.