How to search a website with Loop Parse?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

How to search a website with Loop Parse?

Post by mrmech » 06 Jun 2023, 13:28

I want to copy the file names of eBooks saved on my computer then search Amazon for the book.

Here's how I think it should work:
  • Select several files in Directory Opus (a Windows Explorer replacement)
  • Copy the list of file names (DOpus does this with a shortcut)
  • Parse the list
  • Open a Chrome Tab with an Amazon Search window for each file name
I can parse the list of file names and set the AmazonSearchURL variable to the correct URL.
However, my run command to open the Chrome tab with the Amazon search window fails.

Here's a list of sample files:

Code: Select all

Gary Noesner - Stalling for Time.epub
Geoffrey Gray - Skyjack.mobi
Greg B. Smith - Made Men.mobi
Greg B. Smith - Nothing but Money.mobi
Gregg Olsen - Starvation Heights.epub
Here's my script:

Code: Select all

DIRECTORY_OPUS:					; This label is for the DOpus section of a much larger script
#IfWinActive ahk_exe dopus.exe	; The DOPus section has several commands, only 1 is included below

^+!A::gosub SearchAmazonBooks	; I have a mouse button permanently configured to send ^+!A
								; I included everything above this line in case it's interfering, but I don't think it is
SearchAmazonBooks:				; This label is for the command that needs to be fixed
AmazonBookList :=
AmazonBookListResults :=
AmazonSearchURL :=
Clipboard :=

Send, ^+n						; DOpus shortcut to copy list of file names
ClipWait, 2
   If ErrorLevel {
     MsgBox, 48, Error, An error occurred while waiting for the clipboard.
     Return
     }
	 
AmazonBookList := RegExReplace(Clipboard, "\.(epub|mobi)", "")	 
AmazonBookList := RegExReplace(AmazonBookList, "`r`n", "|")
;-msgbox %AmazonBookList%

Loop, Parse, AmazonBookList, |
{
AmazonSearchURL := "https://www.amazon.com/s?k="StrReplace(A_LoopField, " ", "+")"&i=stripbooks&crid=3H4O3DBRM5QUR&sprefix=testsearch%2Cstripbooks%2C67&ref=nb_sb_noss_1"
Run, chrome.exe %AmazonSearchURL%, C:\Program Files (x86)\Google\Chrome\Application
}
return
Thanks for any help!
Update: I made a correction to the trigger so it actually calls the label SearchAmazonBooks, I added some notes and I removed the counter part of the script.
Last edited by mrmech on 06 Jun 2023, 17:10, edited 6 times in total.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: How to search a website with Loop Parse?

Post by mikeyww » 06 Jun 2023, 13:44

Is this a ChatGPT special?

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: How to search a website with Loop Parse?

Post by mrmech » 06 Jun 2023, 14:12

Nope. Wrote it with my own brain.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: How to search a website with Loop Parse?

Post by mrmech » 06 Jun 2023, 17:08

mikeyww wrote:
06 Jun 2023, 13:44
Is this a ChatGPT special?
I guess you wrote this because there are some confusing parts in my script. I added some notes and removed the Counter variable from the Loop Parse block. Please take another look, Thanks!

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: How to search a website with Loop Parse?

Post by mikeyww » 06 Jun 2023, 19:09

Have you checked to see what the value of AmazonSearchURL is? You can display or examine that value inside your loop.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: How to search a website with Loop Parse?

Post by mrmech » 06 Jun 2023, 19:50

It started working after I restarted my computer. Go figure. :roll:

Thanks for the help!

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: How to search a website with Loop Parse?

Post by mikeyww » 06 Jun 2023, 19:53

Good to hear.

A suggestion for using the forum is to avoid going back to modify a previously posted script. This makes the thread impossible for readers to follow. Instead, simply post a new reply with a revised script. Thank you.

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

Re: How to search a website with Loop Parse?

Post by mrmech » 10 Jun 2023, 08:26

Good advice! Thanks again.

Post Reply

Return to “Ask for Help (v1)”