On Bing's homepage, there's a hyperlink that says "Learn More" at the bottom of the page. When you click on it, there's an explanation of the daily picture shown on their homepage. (sometimes 1 paragraph, sometimes longer than that). I'd like to copy that text (explanation) into clipboard memory. Is this possible to do with AHK?
If that's not possible, then at the very least, I'd like AHK to move my mouse cursor to that link and click it.
Firefox is my primary browser. Thanks.
Is there a way to search for text on a webpage and move the mouse cursor to that position?
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Try the code below. Press Ctrl+F1 to copy the text to the clipboard. You don't need the Bing page open in any browser for it to work.
Code: Select all
^F1::
BingHtml := URLDownloadToVar("https://bing.com")
RegExMatch(BingHtml, "(?<=class=""vs_bs_title"">).*?(?=<)", title)
RegExMatch(BingHtml, "(?<=<span class=""text"" id=""iotd_desc"">).*?(?=<)", text)
Clipboard := title "`n`n" text
MsgBox, 64, Copied to Clipboard, The Bing 'Image of the Day' explanation has been copied to the clipboard., 3
return
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Sorry, but it didn't work. Got the following error message.
Based on the error message, I took a guess and placed the missing bracket here:
When it ran it a 2nd time, I didn't get an error message but nothing got copied.
Based on the error message, I took a guess and placed the missing bracket here:
Code: Select all
hObject.Open("GET",url)
}
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Copy the complete code from the code box, not just the part that is visible in collapsed/default view.
You can use 'Select all', 'Expand View' or scroll to select/see the whole code.
You can use 'Select all', 'Expand View' or scroll to select/see the whole code.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Yeah I got it now. I just realized my error as I was reviewing the code (in my copied file). Thanks guys.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Hi Boiler, the first code you gave me didn't quite work out. It works, but it copies the first paragraph only - it's missing the 2nd paragraph. For example, if you look at the description printed for today, it says:
But there is actually more. If you click on the link that says "Learn More"Happy Star Wars Day!
Sprinting over the sands, this grey seal reminds us of Luke Skywalker's zippy landspeeder vehicle from the first 'Star Wars' flick. But unlike Luke, it's not bound for Tosche Station to pick up some power converters—just to the sea for a fishy snack.
It will reveal the entire text.
Happy Star Wars Day!
Sprinting over the sands, this grey seal reminds us of Luke Skywalker's zippy landspeeder vehicle from the first 'Star Wars' flick. But unlike Luke, it's not bound for Tosche Station to pick up some power converters—just to the sea for a fishy snack.
It looks like we're on Luke's homeworld of Tatooine for Star Wars Day (May the Fourth be with you!). But this is really a beach on England's east coast, far, far away from the Tunisian desert where the 1977 film was shot. As for our seal friend, it was mid-flop just an inch off the ground at the moment this photo was taken. The photo's focus and perspective fool your eye, making the seal seem to hover like Luke's souped-up speeder. Quite the Jedi mind trick!
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
This is the best I can do right now, which is to get it to automatically open the page that has that info on it. When I try to download the source HTML for that page, it gives me search results that don't include that info. I could probably do some brute force stuff to get the text off the page that opens in browser, but that might not be better than just seeing the page since it sounds like that's the main thing you're looking for. Press Ctrl+F1, and it will open the page with the full explanation, and you don't need anything to be already open when you press the hotkey.
Code: Select all
^F1::
BingHtml := URLDownloadToVar("https://bing.com")
RegExMatch(BingHtml, ".{300}(?=Learn more<\/a>)", BingHtmlChunk)
RegExMatch(BingHtmlChunk, "(?<=href="")[^""]+", LearnMoreURL)
LearnMoreURL := StrReplace(LearnMoreURL, "&", "&")
LearnMoreURL := "https://www.bing.com" . StrReplace(LearnMoreURL, """, """")
Run, % LearnMoreURL
return
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Hi Boiler, I appreciate your effort but it's not working.
I tried your most recent code & got the following:
https://i.postimg.cc/FsRcDwzv/bing-sr-incorrect.png
What should be shown when you manually click on the "Learn More" link, you should see this:
https://i.postimg.cc/9fGqDh8d/bing-sr-correct.png
Interestingly enough, the only difference between the URL is the quotation in the 2nd screenshot:
https://www.bing.com/search?q=national+nurses+week&filters=HpDate:"20210506_0700"
When i ran your script, I noticed the URL did not contain the quotation marks wrapped around the date.
I tried your most recent code & got the following:
https://i.postimg.cc/FsRcDwzv/bing-sr-incorrect.png
What should be shown when you manually click on the "Learn More" link, you should see this:
https://i.postimg.cc/9fGqDh8d/bing-sr-correct.png
Interestingly enough, the only difference between the URL is the quotation in the 2nd screenshot:
https://www.bing.com/search?q=national+nurses+week&filters=HpDate:"20210506_0700"
When i ran your script, I noticed the URL did not contain the quotation marks wrapped around the date.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Yes, I know what it's supposed to show, and it works on my machine. It shows the exact page you indicated it's supposed to show. Mine produces the complete URL including the quotation marks wrapped around the date.
To try to troubleshoot, replace Run in the script with MsgBox, and see what it shows when you run it and press the hotkey. You can press Ctrl+C to copy the contents of the MsgBox when it is showing so you can paste it here. Mine copied directly from that MsgBox shows this:
https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
To try to troubleshoot, replace Run in the script with MsgBox, and see what it shows when you run it and press the hotkey. You can press Ctrl+C to copy the contents of the MsgBox when it is showing so you can paste it here. Mine copied directly from that MsgBox shows this:
https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Can you just post it as text rather than a picture that can't be clicked on or copied as text? I told you how you can copy the contents of the MsgBox.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
OK, so now I put that in a proper link below. When you click on it from your machine, does it bring up the proper page? It does on my machine.
https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
I was wrong. There are actually 2 differences in the URLs. One is the quotation marks (already mentioned above) and also when I click on the link manually, this is absent in the URL.
Code: Select all
&form=hpcapt
Last edited by M4verick on 06 May 2021, 10:21, edited 1 time in total.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Yes it does.boiler wrote: ↑06 May 2021, 10:19OK, so now I put that in a proper link below. When you click on it from your machine, does it bring up the proper page? It does on my machine.
https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Then I don't see why it wouldn't work. Can you try this as a stand-alone script and see if it brings up the proper page?:
Code: Select all
Run, https://www.bing.com/search?q=national+nurses+week&form=hpcapt&filters=HpDate:"20210506_0700"
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Same problem as before. I see this:
https://i.postimg.cc/FsRcDwzv/bing-sr-incorrect.png
It's really quite weird what is happening.
https://i.postimg.cc/FsRcDwzv/bing-sr-incorrect.png
It's really quite weird what is happening.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
I figured it must be the difference in browsers, and sure enough, when I run it in Edge, I get what you get. For some reason, Edge modifies the URL. I suppose you are using Edge as your default browser. If you have Chrome installed, change the the Run line in the script to the following:
Code: Select all
Run, % "chrome.exe " LearnMoreURL
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
Nope, Firefox is my default browser of choice.boiler wrote: ↑06 May 2021, 10:33I figured it must be the difference in browsers, and sure enough, when I run it in Edge, I get what you get. For some reason, Edge modifies the URL. I suppose you are using Edge as your default browser. If you have Chrome installed, change the the Run line in the script to the following:Code: Select all
Run, % "chrome.exe " LearnMoreURL
I don't have Google Chrome installed but I do have Vivaldi which is Chrome based I think. I'll be right back.
EDIT:
I just tried Vivaldi browser and the URL in the address bar was... LOL
http://learnmoreurl
Last edited by M4verick on 06 May 2021, 10:42, edited 1 time in total.
Re: Is there a way to search for text on a webpage and move the mouse cursor to that position?
OK. It's the same issue with Firefox. There may be a way to run it as if you pasted it into the URL entry field rather than whatever it (and Edge) does to modify it, but I don't know how to do that. One workaround I can think of would be to add that link to a GUI and have the script click on its own link then close the GUI. So a small GUI would just briefly flash on the screen before opening the browser window.
Who is online
Users browsing this forum: anogoya, Descolada, Google [Bot], Mannaia666, skeerrt and 149 guests