Tinker
September 1, 2023, 3:44pm
1
Overview
So I can use AppleScript to get the Title of a page using:
tell application "Google Chrome" to return title of active tab of front window
If I have, for example, the page https://www.amazon.co.uk/Agua-Brava-Men-EDC-Splash/dp/B000E7YK0U/ open, I can see the current price is £22.86
.
Can I use Applescript (or Javascript) to somehow fetch this value? (It can be the approximate price, it doesn't need to be exact. So, £22
or 22
would be acceptable)
When I view source for that page I find:
<span class="a-price a-text-price a-size-medium apexPriceToPay" data-a-size="b" data-a-color="price"><span class="a-offscreen">£22.86</span><span aria-hidden="true">£22.86</span></span>
How could I use AppleScript or Javascript to get £22.86
for me? (I want to assign it to a variable called DaPrice
)
tiffle
September 1, 2023, 4:23pm
2
Using AppleScript is unnecessary as you can use the built-in KM token %FrontBrowserTitle% or %ChromeTitle%
For other browser-related tokens consult the KM wiki here token:WebBrowserTokens [Keyboard Maestro Wiki]
As for your real question you might want to consider using XPath. I’m no expert so search the KM forum for examples of its use.
1 Like
Here’s an example of how to use the xPath to get the price... however, since Amazon is a obscenely bloated website, I am fairly certain there are enough variations for each page that the xPath changes dynamically, and while this works for me , and on the page I use in the example , I HIGHLY doubt this is a reliable method to get prices across multiple pages. But YMMV.
Download Macro(s): Get Amazon Price Using xPath.kmmacros (7.7 KB)
Macro-Image
Macro-Notes
Macros are always disabled when imported into the Keyboard Maestro Editor.
The user must ensure the macro is enabled.
The user must also ensure the macro's parent macro-group is enabled.
System Information
macOS 13.5.1
Keyboard Maestro v10.2
2 Likes
Tinker
September 3, 2023, 12:51pm
4
Thank you , I was not aware!
1 Like
Tinker
September 3, 2023, 7:45pm
5
is there a built in token for a copying in image in the front browser? (I didn't see it on the list ) so I guess not
Tinker
September 3, 2023, 7:47pm
6
wow thanks for taking the time to have a go. I will attempt to get my head around it!
1 Like
Not that I’m aware of. I highly doubt it since the front browser page could have any number of images.
1 Like
tiffle
September 3, 2023, 8:22pm
8
No but since you’re new to this forum you might do well to remember that it’s easy to search which is what I did and came up with this:
I have an image that I need to routinely copy/save. It is on a web page (specifically an extension, but essentially it's HTML) and it only shows when a dialog is shown.
I have created a script that opens the dialog, then I need to right-click and copy that image to clipboard). I have tried initiating a right click on the image by finding an element that will always follow the image, then move up by 50 pixels and fo the right click. This brings up the browser's context men, where I then do a Fou…
I don’t know if that will be useful to you - only you can say.