• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

06: Chrome and AutoHotkey: Getting lists from page

Automating and ChromeHere we continue with GeekDude working with Chrome and AutoHotkey extracting data from a webpage.  This session we focus on getting lists and leverage JSON, Chrome.Jxon_Dump, JSON.stringify, Chrome.Jxon_Load and jQuery.

The great news is that GeekDude explained how we can see the Reddit site the way it was the below video!

By logging into https://old.reddit.com/r/AutoHotkey/, the HTML will be the same as in the video!

Chrome and AutoHotkey: Getting lists from page

donate to GeekDudeIf you’re loving this, please consider donating to GeekDude!

Notes: Chrome and AutoHotkey: Getting lists from page

00:05     Sometimes you want multiple items from a page.  Maybe all post titles, or all links form comments.

00:20     Looking in HTML we see there’s a lot going on.  We need to look at the structure BEFORE we get working on it.

Continue reading

05: Automating Chrome with AutoHotkey & getting data from page (part 1)

Automating Chrome with AutoHotkeyWhen GeekDude and I recorded this topic, it was over an hour long so I broke it into two parts.  This session covers how to get content from a page.

The great news is that GeekDude explained how we can see the Reddit site the way it was the below video!

By logging into https://old.reddit.com/r/AutoHotkey/, the HTML will be the same as in the video!

Automating Chrome with AutoHotkey & getting data from page

donate to GeekDudeIf you’re loving this, please consider donating to GeekDude!
Notes from Automating Chrome with AutoHotkey & getting data from page

Scraping data with Chrome and AutoHotkey

00:30     Let’s scrape from the AutoHotkey subreddit  https://www.reddit.com/r/AutoHotkey/

00:42     Maybe you want to get all of the links to the comment section.  Or maybe the titles for all of them for text analysis.

Continue reading

04: Automating Chrome to Set Text & Click a button

Automating Chrome with AutoHotkey

In the fourth session with GeekDude we look at out to Chrome and AutoHotkeyautomate setting text in a search field and then hitting the button to submit the search.

Automating Chrome to Set Text & Click a button

donate to GeekDudeIf you’re loving this, please consider donating to GeekDude!

AutoHotkey script for Automating Chrome to Set Text & Click a button

#Include   ;Remember to put Chrome in your library folder

page:=Chrome.GetPageByTitle("AutoHotkey Community","contains") ;This will connect to the second index of a specific tab
If !IsObject(page){
MsgBox % "That wasn' t object / the page wasn't found"
page.Evaluate("document.querySelector('#keywords').value ='Chrome.ahk'")
Variable =document.querySelector('#keywords').value ='Chrome.ahk'
page.Evaluate("document.querySelector('#keywords').value ='" var "'")
page.Evaluate("document.querySelector('#search > fieldset > button').value ='Chrome.ahk'")

Notes for Automating Chrome to Set Text & Click a button

00:36     Go to AutoHotkey.com/boards/

00:44     Connect to tab using Chrome.GetPageByTitle(“AutoHotkey Community”) ;the default matchtype is “starts with”

01:23     Look at page structure using right-click and Inspect.  This opends Devtools with that element selected.

01:46     It has an ID of “keywords”, copy js path.  Which will give you queryselector(“#keywords”)

02:26     Use the .value to set some text in that box.

03:00     page.Evaluate(“document.querySelector(‘#keywords’).value =’Chrome.ahk'”)

04:01     Make sure inside the JavaScript you use the “=”, not “:=”

04:15     Some people don’t want to have to learn JavaScript.  When using Chrome, you’re going to have to learn JavaScript.

04:56     When using Chrome.ahk, we’re injecting JavaScript.  So best to learn

05:54     The button is right next to the input.  You can go back to the page and right-click the button, then hit Inspect

06:13     Test the new js path.  Instead of using .value, use .click

06:42     Test in Chrome developer tool

07:18     When running an Evaluate method, it waits for the previous Evaluate to finish (so no need to sleep between them).

07:44     If you run into a problem where you think it is happening too quickly, check the forum for some solutions

08:40     Sometimes what you want to input won’t always be a static string.  If you’re trying to reference a variable, you need to use the expression syntax.  In an expression, you’re not just assigning text, you’re doing math or making function calls.

Variable =document.querySelector(‘#keywords’).value =’Chrome.ahk’


page.Evaluate(“document.querySelector(”#keywords ‘).value ='” variablevar:=”duh”

page.Evaluate(“document.querySelector(‘#keywords’).value ='” var “‘”) “‘”)

10:48     This works because AutoHotkey splits everything up on a given line.   First is a name of a function, then says this is inside the function, then this is text inside a function.  Then builds from left to right as to the string that will be used.

12:15     AutoHotkey proceeds left to right when evaluating an expression

12:40     when you use := you’re in expression assignment mode.

13:25     With just single = you’re in plain-text mode.  It reads it as text

15:00     When automating a site, you don’t know what kind of buffer’s they have to prevent scraping / botting.

15:49     When you start automating, you might start seeing Captcha’s everywhere

16:04     Sites get really good at looking like a normal site to a user, but looking like an impenetrable fortress to code

16:36     If your variable contains a single quote or other special charachters, JavaScript will interpret it as code instead of text.

17:13     JavaScript string escape sequence will replace characters with special escape sequences

Not mentioned in Video but GeekDude wrote me after

You can escape JavaScript code using Coco’s JSON library does actually do that escaping that we discussed when talking about putting data on the page. The syntax for invoking it looks like this:

variable = 123`r`n456’quote”quote

page.Evaluate(“document.querySelector(‘#whatever’).value = ” Chrome.Jxon_Dump(variable))

The dump function will automatically escape anything that needs escaped and add quotes to anything that needs quotes.



03: How to Automate Chrome to Navigate to a page and Set text

Chrome and AutoHotkey

Automating Chrome with AutoHotkey

In this session with GeekDude we cover how to navigate to a page, use JavaScript, and set text on a page / element.

donate to GeekDudeIf you’re loving this, please consider donating to GeekDude!

Script from Call

My notes from the session

00:30     Navigate to

00:50     connect to page

01:45     Call the DevTools function Page.Navigate  “https://p.ahkscript.org/”)

02:38     you need to call it by using page.Call(“Page.navigate”,{“url”:“https://p.ahkscript.org/”})

03:00     Look at parameters of Page.Navigate to understand what you need to pass

04:07     You can use page.WaitForLoad() to make sure the page loads (but it isn’t always needed).  Sometimes it waits too long or not long enough.  Check the forum thread for possible help

05:00     You might want to adapt some of their code to update GeekDude’s Chrome class

06:10     Make sure your page grabs the title of the right page (as it can update)

06:40     Put text into page element using JavaScript.  The input field on p.ahkscript.org isn’t a normal edit field.  Many sites have more-advanced field types

07:34     Inspect the page source.  This website imports a script called ace.js

<script src=”https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.7/ace.js” type=”text/javascript” charset=”utf-8″></script>

08:30     It has it’s own JavaScript API.  So when you want to talk to an Ace control, you need to talk in it’s language.  You’ll need to evaluate your site to see what it is using…  Always look for how to work with it using JavaScript.  When you’re using Chrome.ahk everything you’re doing is running through JavaScript!

8:57        You’re using AutoHotkey to run the JavaScript to drive Chrome.

9:00        In https://p.ahkscript.org/index.js you can see how that page talks to Ace. It could give you information on how to do it.  Mimic what the page itself is doing.   Not all sites are as easy as this to see what does

10:00     In this example, It creates an Editor variable and calls all of the editor commands on that.

10:23     Look back to Ace.js documentation you can see Editor is a section of the documentation.  This shows all the different methods to communicate with an Ace control.

10:47     Since we want to set text look for one that does that.  We’ll use Insert  function (Inserts text into wherever the cursor is pointing.)  Insert(String text)

11:15     In the  pastebin code’s index.js we see everything is called with editor dot (editor.) method name

11:25     We’ll prototype our JavaScript code from the Chrome developer tools because those give better immediate feedback (debugging info) of what went wrong.  Once we have a working line of JavaScript we’ll put that in AutoHotkey.

11:30     Go to Console within the Chrome debugging view (Control+Shift+i)

11:48     Look for the variable Editor by typing Editor.  It should respond showing you that it exists and is available

11:56     Auto-Assist works.  Try typing Editor.Insert (because insert is a method) .  Give it some text to test.

editor.insert(“hello world”)

12:17    The text should show up on the pastebin page.  😊

12:28     Take it over to your AutoHotkey code and try it from there using Page.Evaluate

12:42     The Double quotes are a problem because ahk and JavaScript both use them.

13:00     You could use the legacy assignment to set it.  But this gives us 2 lines of code

13:40     Thankfully JavaScript can use single quotes  most of the time.

page.Evaluate(“editor.insert(‘hello world’)”)

14:00     The Evaluate Method- that’s saying “evaluate the JavaScript” as it is using the same functionality as putting JavaScript in the Chrome development tools console and hitting Enter.  It runs it through the same interface.  Evaluate is short for “Take this JavaScript, run it on the page, and return the result.

14:53     Maybe your JavaScript has a ” that you want .   AutoHotkey requires you to double-up the quotes  “” (basically it escapes the second one).  AutoHotkey will reduce it from two quotes to one quote.

15:30     Maybe the page your using is simpler.  A lot of places have very simple pages.  They’ll just have standard input control which you can access with standard JavaScript.  Another site is mytextarea.net

16:12     Inspect the code for mytextarea.net  and you’ll see it is literally just a textbox

16:20     Let’s navigate to that page.  You’ll see we have to find a different way to connect as every page is unique.

17:16     When you’re writing JavaScript to a page you don’t know much about, one of the biggest problems you’re going to have is how do I get it to act on just this part of the page, this element, this box?

17:31     When in DevTools console, right click on the element you want, then Copy, and select Copy JS path (Selector is also helpful)

18:00     This returns the JavaScript code that that can be used to access that element (it is the Path to it)

18:00     So use that path, then we want to get it’s value

document.querySelector(“body > textarea”).value

18:48     this uses QuerySelector which returns the first instance.  QuerySelectorAll returns an array.

20:14     As long as you copy js Path you’ll probably get something useful (not sure if it is the DOM or how it is decided)

20:20     Any tools you can use like iWB2 learner tool for Chrome- No, GeekDude not aware

21:00     Here we’ve access a value.  Let’s set a new value

document.querySelector(“body > textarea”).value =’fruit’

21:26     Now take this from the Devtools and put it into AutoHotkey.  Make sure you replace double quotes with single quotes  page.Evaluate(“document.querySelector(‘body > textarea’).value =’taco'”)

21:30     Make sure the title / URL is the correct one