https://www.youtube.com/watch?v=GoMtClsteg8
I'm sure AHK could help with atleast part of my job
Thanks in advance
I made a video about my question
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: I made a video about my question
Interesting idea on what you're wanting. I can't help you because I'm never good with AHK and HTML coming together.
You'd probably want to look for "html find specific information," somewhere in the forums or online.
Good luck
You'd probably want to look for "html find specific information," somewhere in the forums or online.
Good luck
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
Re: I made a video about my question
I'd be willing to help when I get home tonight but that's 5 hours from now
Re: I made a video about my question
You've to download the Chilis index page "/locations/us/all" -> UrlDownloadToFile
Parse its sourcecode for the states and its towns ... -> RegExMatch
... to be able to create direct links like "https://www.chilies.com/locations/us/arizona/chandler" to download that pages ...
... to parse for its specific address field elements -> COM
... to push that content directly into a google sheet -> COM
There's a good chance that you'll find all necessary code snippets at the forum.
Good luck
Parse its sourcecode for the states and its towns ... -> RegExMatch
... to be able to create direct links like "https://www.chilies.com/locations/us/arizona/chandler" to download that pages ...
... to parse for its specific address field elements -> COM
... to push that content directly into a google sheet -> COM
There's a good chance that you'll find all necessary code snippets at the forum.
Good luck
Re: I made a video about my question
What does the COM mean here, Bobo?
That sounds good Donovv, I'll check back here irregularly throughout the day.
That sounds good Donovv, I'll check back here irregularly throughout the day.
Re: I made a video about my question
well heres a start
edit: code now msgbox's the full address(street address, city, state, zip) and the phone number
edit2: added simple gui so you can copy the webpage pressing ok runs script opening the msgbox
edit: code now msgbox's the full address(street address, city, state, zip) and the phone number
edit2: added simple gui so you can copy the webpage pressing ok runs script opening the msgbox
Code: Select all
f1::
gui add, text,,please enter the webaddress of the page you would like to get the info for
gui add, edit, vwebsite,
gui add, button, ,ok
gui show
return
buttonok:
gui submit
wb := ComObjCreate("InternetExplorer.Application")
wb.visible := 1
wb.navigate(website)
while wb.busy
sleep 10
stores := wb.document.getElementsByclassname("street-address").length
addr := array() ; array with the address of the store for the page your on
while a_index <= stores
addr.push(wb.document.getElementsByclassname("street-address")[a_index-1].innertext)
city := array()
while a_index <= stores
city.push(wb.document.getElementsByclassname("locality")[a_index-1].innertext)
state := array()
while a_index <= stores
state.push(wb.document.getElementsByclassname("region")[a_index-1].innertext)
zip := array()
while a_index <= stores
zip.push(wb.document.getElementsByclassname("postal-code")[a_index-1].innertext)
phone := array()
while a_index <= stores
phone.push(wb.document.getElementsByclassname("location-phone")[a_index-1].href)
while a_index <= stores
{
phone1 := % phone[a_index]
stringtrimleft,phone1,phone1,4
msgbox % "address ="addr[a_index]"`n"city[a_index]", "state[a_index]", "zip[a_index]"`n phone number= "phone1
}
return
Re: I made a video about my question
Hi Klyde
If you can understand what is being explained by the above responses, by all means, stop reading now.
There are many ways to do what you are wanting very elegantly, all hidden in the background where the user does not see the actions and I am sure that everyone offering suggestions have the best intentions with their advice. However, seeing that this is your first post, I suspect that all the advice and help might be above your skill level at the moment. I can still remember how I started with AHK and got a lot of the same kind of help that meant rather little at the time and only frustrated me because I thought it was the only way. Much like you, I started with high-lite on a website with the mouse, copy, alt-tab, use arrows to move and paste, rinse repeat. Now this is not the neat and tidy way to do things and it takes a million times longer to do the same thing and you can not do other things while it is working, but it gets the job done, usually...
So to answer your questions in your video:
1 - As part of the AHK installation there should be a Window Spy application. This give a bunch of useful information which includes the mouse location, note that you have 3 different positions and which one you use will depend on how you are wanting to use it. So now you have the actual location.
1b - If you do not have Window Spy for some reason, AHK can give you the cursor location with a command https://autohotkey.com/docs/commands/MouseGetPos.htm
1b1- You can use message boxes so that you can see the value of a variable (you can also use tooltip that can show you as and when a variable changes but it needs some code) https://autohotkey.com/docs/commands/MsgBox.htm
2 - https://autohotkey.com/docs/commands/MouseMove.htm will let you move the mouse around the screen
3 - https://autohotkey.com/docs/commands/Send.htm lets you send physical actions to the pc
4 - A recommendation I have is not to use the mouse for collecting information as far as possible but rather keystrokes as it is more reliable in my experience. So, for example, do not click the cell below the last in your spreadsheet one but rather use the keyboard to move down a cell.
Bonus points - Start using functions early, they are very useful and make easy to maintain and re-use code. You are already using them when you use a default command but the format is slightly different. The biggest advantage here is that you can get a quick and nasty script working and use it while still improving on it. If your improvement does not work, keep using the old function, when you new one works, switch over to that. A function does 1 thing, it takes a bunch of stuff and gives ONE result or a SINGLE action (yes you can make it do more than one thing or give 2 answers but that is not the norm).
So lets start with getting the address: ( I assume you have used the Window Spy to get the right side of the address and the left side of the address)
So this is a first function, all it does is select the text between 200,100 and 100,100 as you can see in the code, sets the clipboard to whatever was copied from there and returns that, but it can not work on it's own. You need to call it in your main program.
This is your main program, short and simple.
Stick these together one after the other in a script and you will have a working example of how to get text from your browser in a quick and nasty way. NOTE - there are more elegant ways to do this but not as simple and strait forward. You may also find that some applications will not let you copy and paste so this way has some limitations. Go put them together and test it.
Seriously, put them together and look how they work...... do it.....
So what if we want to get text from 200, 100 to 100, 100 as we did above but maybe also in a different script want to get from 300, 200 to 200, 200? We can make a minor change to our getaddress function and it is more flexible. It still does the exact same thing but it can be used for more than 1 task. So your complete program looks like this:
Now in your main program, you can now create a variable and use the getaddress function we have created to get the text from between 2 points you decide when you create the variable and call the getaddress function. No need to go and change the function at all.
Now, I will leave you to:
1 - switch to your spreadsheet
2 - navigate to the last cell in your address column, go one further down and paste the variable "MyResult"
If you can understand what is being explained by the above responses, by all means, stop reading now.
There are many ways to do what you are wanting very elegantly, all hidden in the background where the user does not see the actions and I am sure that everyone offering suggestions have the best intentions with their advice. However, seeing that this is your first post, I suspect that all the advice and help might be above your skill level at the moment. I can still remember how I started with AHK and got a lot of the same kind of help that meant rather little at the time and only frustrated me because I thought it was the only way. Much like you, I started with high-lite on a website with the mouse, copy, alt-tab, use arrows to move and paste, rinse repeat. Now this is not the neat and tidy way to do things and it takes a million times longer to do the same thing and you can not do other things while it is working, but it gets the job done, usually...
So to answer your questions in your video:
1 - As part of the AHK installation there should be a Window Spy application. This give a bunch of useful information which includes the mouse location, note that you have 3 different positions and which one you use will depend on how you are wanting to use it. So now you have the actual location.
1b - If you do not have Window Spy for some reason, AHK can give you the cursor location with a command https://autohotkey.com/docs/commands/MouseGetPos.htm
1b1- You can use message boxes so that you can see the value of a variable (you can also use tooltip that can show you as and when a variable changes but it needs some code) https://autohotkey.com/docs/commands/MsgBox.htm
2 - https://autohotkey.com/docs/commands/MouseMove.htm will let you move the mouse around the screen
3 - https://autohotkey.com/docs/commands/Send.htm lets you send physical actions to the pc
4 - A recommendation I have is not to use the mouse for collecting information as far as possible but rather keystrokes as it is more reliable in my experience. So, for example, do not click the cell below the last in your spreadsheet one but rather use the keyboard to move down a cell.
Bonus points - Start using functions early, they are very useful and make easy to maintain and re-use code. You are already using them when you use a default command but the format is slightly different. The biggest advantage here is that you can get a quick and nasty script working and use it while still improving on it. If your improvement does not work, keep using the old function, when you new one works, switch over to that. A function does 1 thing, it takes a bunch of stuff and gives ONE result or a SINGLE action (yes you can make it do more than one thing or give 2 answers but that is not the norm).
So lets start with getting the address: ( I assume you have used the Window Spy to get the right side of the address and the left side of the address)
Code: Select all
getaddress()
{
sleep, 50 ;gives a 50ms pause for the pc to let things happen, it might need to be faster or slower and will depend on your system and the application that you are working on
mousemove, 200, 100 ;moves the mouse
sleep, 50
send, {click down} ;sends a left cluck down
sleep, 50
mousemove, 100, 100 ;moves the mouse, this with the previosu click down and the next click up give the select action bus is actually 3 separate actions
sleep, 50
send, {click up}
sleep, 50
clipboard := "" ;sets your clipboard to be blank
send, {ctrl down}c{ctrl up} ;again 3 actions but effectivly a windows copy command
if (clipboard == "") ;this does some checking on if you coppied something and if nothing, it will exit
{
msgbox, there is an error with getaddress function, program will exit...
exitapp ;exits your program and you will have to restart it
}
return, %clipboard%
}
Code: Select all
f1::
MyResult := getaddress() ;MyResult variable is set to be whatever the function "getaddress" gives as an answer
msgbox, %MyResult% ;uses message box to tell you what MyResult's value is
return ;ends your program and will let you run it again if needed
}
Stick these together one after the other in a script and you will have a working example of how to get text from your browser in a quick and nasty way. NOTE - there are more elegant ways to do this but not as simple and strait forward. You may also find that some applications will not let you copy and paste so this way has some limitations. Go put them together and test it.
Seriously, put them together and look how they work...... do it.....
So what if we want to get text from 200, 100 to 100, 100 as we did above but maybe also in a different script want to get from 300, 200 to 200, 200? We can make a minor change to our getaddress function and it is more flexible. It still does the exact same thing but it can be used for more than 1 task. So your complete program looks like this:
Code: Select all
f1::
MyResuly := getaddress(300, 200, 200, 200) ;We send the parameters of the start and ending of the text we want. Change these to something else and see what happens
msgbox, %MyResult%
return
getaddress(x1, y1, x2,y2) ;note the 4 parameters sent to the function. The getaddress function is going to use these as the locations from where to get the text
{
sleep, 50 ;gives a 50ms pause for the pc to let things happen, it might need to be faster or slower and will depend on your system and the application that you
are working on
mousemove, %x1%, %y1% ;moves the mouse, note you are using the parameters received
sleep, 50
send, {click down} ;sends a left cluck down
sleep, 50
mousemove, %x2%, %y2% ;moves the mouse, again we use the received parameters, this with the previous click down and the next click up give the select action bus is actually 3 separate actions
sleep, 50
send, {click up}
sleep, 50
clipboard := "" ;sets your clipboard to be blank
send, {ctrl down}c{ctrl up} ;again 3 actions but effectively a windows copy command
if (clipboard == "") ;this does some checking on if you copied something and if nothing, it will exit
{
msgbox, there is an error with getaddress function, program will exit...
exitapp
}
return, %clipboard%
}
Now, I will leave you to:
1 - switch to your spreadsheet
2 - navigate to the last cell in your address column, go one further down and paste the variable "MyResult"
Re: I made a video about my question
so this is a semi working script it gets all the info
go to your spreadsheet on goggle docs click a cell and press copy cell link then past it as shown in the code pm me if you need help
go to your spreadsheet on goggle docs click a cell and press copy cell link then past it as shown in the code pm me if you need help
Code: Select all
global addrrow := "b"
global cityrow := "c"
global staterow := "d"
global ziprow := "e"
global phonerow := "f"
global col := 2
f1::
gui add, text,,please enter the webaddress of the page you would like to get the info for
gui add, edit, vwebsite,
gui add, button, ,ok
gui show
return
buttonok:
gui submit
global wb := ComObjCreate("InternetExplorer.Application")
wb.visible := 1
wb.navigate(website)
while wb.busy
sleep 10
stores := wb.document.getElementsByclassname("street-address").length
addr := array() ; array with the address of the store for the page your on
while a_index <= stores
addr.push(wb.document.getElementsByclassname("street-address")[a_index-1].innertext)
city := array()
while a_index <= stores
city.push(wb.document.getElementsByclassname("locality")[a_index-1].innertext)
state := array()
while a_index <= stores
state.push(wb.document.getElementsByclassname("region")[a_index-1].innertext)
zip := array()
while a_index <= stores
zip.push(wb.document.getElementsByclassname("postal-code")[a_index-1].innertext)
phone := array()
while a_index <= stores
phone.push(wb.document.getElementsByclassname("location-phone")[a_index-1].href)
while a_index <= stores
{
phone1 := % phone[a_index] ; %
addr1 := % addr[a_index] ;%
city1 := % city[a_index] ;%
state1 := % state[a_index] ;%
zip1 := % zip[a_index] ;%
stringtrimleft,phone1,phone1,4
sendaddr(addr1)
sendcity(city1)
sendstate(state1)
sendzip(zip1)
sendphone(phone1)
col++
}
return
sendaddr(addr)
{
website := % "https://docs.google.com/spreadsheets/d/16M83S-S1XJde5aUGsvljE4FWtfmAmwWcWjwQhngvf-U/edit#gid=0&range=" addrrow col ;% change all of these to be the webaddress of your spreadsheet
wb.navigate(website)
sleep 5000
while wb.busy
sleep 10
send, %addr%
send, {enter}
return
}
sendcity(addr)
{
website := % "https://docs.google.com/spreadsheets/d/16M83S-S1XJde5aUGsvljE4FWtfmAmwWcWjwQhngvf-U/edit#gid=0&range=" cityrow col ;% change all of these to be the webaddress of your spreadsheet
wb.navigate(website)
sleep 1000
while wb.busy
sleep 10
send, %addr%
send, {enter}
return
}
sendstate(addr)
{
website := % "https://docs.google.com/spreadsheets/d/16M83S-S1XJde5aUGsvljE4FWtfmAmwWcWjwQhngvf-U/edit#gid=0&range=" staterow col ;% change all of these to be the webaddress of your spreadsheet
wb.navigate(website)
sleep 1000
while wb.busy
sleep 10
send, %addr%
send, {enter}
return
}
sendzip(addr)
{
website := % "https://docs.google.com/spreadsheets/d/16M83S-S1XJde5aUGsvljE4FWtfmAmwWcWjwQhngvf-U/edit#gid=0&range=" ziprow col ;% change all of these to be the webaddress of your spreadsheet
wb.navigate(website)
sleep 1000
while wb.busy
sleep 10
send, %addr%
send, {enter}
return
}
sendphone(addr)
{
website := % "https://docs.google.com/spreadsheets/d/16M83S-S1XJde5aUGsvljE4FWtfmAmwWcWjwQhngvf-U/edit#gid=0&range=" phonerow col ;% change all of these to be the webaddress of your spreadsheet
wb.navigate(website)
sleep 1000
while wb.busy
sleep 10
send, %addr%
send, {enter}
return
}
Re: I made a video about my question
What I have been doing to get to grips with ahk is using Pulover's macro maker, I'm not a programmer never will be, but my approach is simple, I record what I want to do and then go through the code of the script it creates and attempt to simplify it. Now after only 5 days I'm using com's and expression's in the script. I can then export it as a ahk script. Just an option, like I said if I didn't have the macro maker to paint the ideas on a canvas I would have given up by now, code to me looks like gobildy goop, I cant think in linear terms and logic is an anathema to me. However what I do know is this community is very supportive and that's why I'm persevering with ahk.