copy google define definitions and write them in a text file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mutantGOD-
Posts: 9
Joined: 22 Oct 2022, 09:31

copy google define definitions and write them in a text file

Post by mutantGOD- » 22 Oct 2022, 09:47

i have a list of words and all of the words are verbs. i want to automatically copy definitions of the verbs with google define and save them as a new text file like in the screen shot

notice: sometimes there`s no number about the difinition version like the number 1 in the screenshot

it has to detect the word verb and a number infront of the definition
Screenshot_2.png
Screenshot_2.png (208.88 KiB) Viewed 794 times
mutantGOD-
Posts: 9
Joined: 22 Oct 2022, 09:31

Re: copy google define definitions and write them in a text file

Post by mutantGOD- » 22 Oct 2022, 11:07

here`s the verbs list
verbs to define.txt
(13.89 KiB) Downloaded 18 times
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 22 Oct 2022, 12:00

Welcome to this AutoHotkey forum!

A few ideas are below. Adjust as needed.

Code: Select all

dir   = %A_ScriptDir%
words = %dir%\words.txt
out   = %dir%\definitions.txt
If !FileExist(words) {
 MsgBox, 48, Error, File not found.`n`n%words%
 Return
}
ToolTip, Working....
SoundBeep, 1500
FileRecycle, %out%
Loop, Read, %words%, %out%
 FileAppend, % Trim(A_LoopReadLine) " " def(Trim(A_LoopReadLine, " =")) "`n"
ToolTip
Run, %out%

def(word) {
 Static file := A_ScriptDir "\out.html"
 UrlDownloadToFile, https://www.google.com/search?q=define+%word%, %file%
 If !ErrorLevel {
  FileRead, html, %file%
  FileRecycle, %file%
  RegExMatch(html, "(<div class=[^>]+?>){2}\K[a-z ,()]{2,}", def)
  Return def
 } Else MsgBox, 48, Error, An error occurred during the download.`n`n%url%
}
crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

Re: copy google define definitions and write them in a text file

Post by crypter » 22 Oct 2022, 15:54

If it says "noun" before "verb" it does not work, it doesn't copy the definition
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 22 Oct 2022, 16:09

It's just an example. You may need to adjust.
mutantGOD-
Posts: 9
Joined: 22 Oct 2022, 09:31

Re: copy google define definitions and write them in a text file

Post by mutantGOD- » 22 Oct 2022, 18:40

mikeyww wrote:
22 Oct 2022, 16:09
It's just an example. You may need to adjust.
it doesn`t work

i tried the attached list, plz test it
words.txt
(478 Bytes) Downloaded 23 times
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 22 Oct 2022, 20:42

My script worked in my brief test, but the regex would likely need adjustment. There may be a Google API to improve efficiency and reliability. I was offering an idea but do not have full knowledge of the formats that Google uses for these pages. You might be able to deduce them by examining a larger sample of output.
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: copy google define definitions and write them in a text file

Post by garry » 23 Oct 2022, 02:02

@mikeyww your script works fine ( used less words )

Code: Select all

words := a_scriptdir . "\words.txt"
out   := a_scriptdir . "\definitions.txt"
;- example with few words :
ifnotexist,%words%
{
e:="
(Ltrim Join`r`n
afford    =
affix     =
age       =
aggregate =
allow     =
)"
fileappend,%e%,%words%,utf-8
}
If !FileExist(words) {
 MsgBox, 48, Error, File not found.`n`n%words%
 Return
}
;-------------------
ToolTip, Working....
SoundBeep, 1500
FileRecycle, %out%
Loop, Read, %words%, %out%
 FileAppend, % Trim(A_LoopReadLine) " " def(Trim(A_LoopReadLine`, " =")) "`r`n"
ToolTip
Run, %out%
exitapp
;-----------
def(word) {
 Static file := A_ScriptDir "\out.html"
 UrlDownloadToFile, https://www.google.com/search?q=define+%word%, %file%
 If !ErrorLevel {
  FileRead, html, %file%
  FileRecycle, %file%
  RegExMatch(html, "(<div class=[^>]+?>){2}\K[a-z ,()]{2,}", def)
  Return def
 } Else MsgBox, 48, Error, An error occurred during the download.`n`n%url%
}
esc::exitapp
;=============================
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 23 Oct 2022, 05:35

Thanks for the testing & feedback, garry. For mutantGOD, the Web has various regex tutorials in case needed to do some tuning. I can't say it's easy to learn, but on the other hand, the price is free!
mutantGOD-
Posts: 9
Joined: 22 Oct 2022, 09:31

Re: copy google define definitions and write them in a text file

Post by mutantGOD- » 23 Oct 2022, 07:31

garry wrote:
23 Oct 2022, 02:02
@mikeyww your script works fine ( used less words )

Code: Select all

words := a_scriptdir . "\words.txt"
out   := a_scriptdir . "\definitions.txt"
;- example with few words :
ifnotexist,%words%
{
e:="
(Ltrim Join`r`n
afford    =
affix     =
age       =
aggregate =
allow     =
)"
fileappend,%e%,%words%,utf-8
}
If !FileExist(words) {
 MsgBox, 48, Error, File not found.`n`n%words%
 Return
}
;-------------------
ToolTip, Working....
SoundBeep, 1500
FileRecycle, %out%
Loop, Read, %words%, %out%
 FileAppend, % Trim(A_LoopReadLine) " " def(Trim(A_LoopReadLine`, " =")) "`r`n"
ToolTip
Run, %out%
exitapp
;-----------
def(word) {
 Static file := A_ScriptDir "\out.html"
 UrlDownloadToFile, https://www.google.com/search?q=define+%word%, %file%
 If !ErrorLevel {
  FileRead, html, %file%
  FileRecycle, %file%
  RegExMatch(html, "(<div class=[^>]+?>){2}\K[a-z ,()]{2,}", def)
  Return def
 } Else MsgBox, 48, Error, An error occurred during the download.`n`n%url%
}
esc::exitapp
;=============================
can you test it with this text file
file2.txt
(413 Bytes) Downloaded 16 times
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 23 Oct 2022, 08:07

mutantGOD, what did your test show? You can post your output file. Ensure that file paths match what is in the script.

Code: Select all

bare (of a person or part of the body) not clothed or covered
bargain an agreement between two or more parties as to what each party will do for the other
bark the sharp explosive cry of certain animals, especially a dog, fox, or seal
bat (of a team or a player in sports such as baseball) take in turns the role of hitting rather than fielding
batch a quantity or consignment of goods produced at one time
bath an act or process of immersing and washing one
batter strike repeatedly with hard blows
...
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: copy google define definitions and write them in a text file

Post by garry » 23 Oct 2022, 08:32

yes , it worked ...

Code: Select all

bare
bargain
bark
bat
batch
bath
batter
be
beam
bear
beat
become
bed
beg
begin
behead
believe
belittle
belong
belt
benefit
best
bet
better
beware
bicycle
bid
big
bike
bill
bin
bind
bird
bisect
bite
black
bleed
blend
blind
block
blood
blunder
board
bob
bomb
bone
book
boomerang
boot
bore
born
borrow
boss
bother
bottom
bound
box
brace
bracket
braid
brain
;=====================================================
bare (of a person or part of the body) not clothed or covered
bargain an agreement between two or more people or groups as to what each will do for the other
bark the sharp explosive cry of a dog, fox, or seal
bat an implement with a handle and a solid surface, typically of wood, used for hitting the ball in games such as cricket, baseball, and table tennis
batch a quantity or consignment of goods produced at one time
bath a large container for water, used for immersing and washing the body
batter strike repeatedly with hard blows
be exist
beam a long, sturdy piece of squared timber or metal used to support the roof or floor of a building
bear carry the weight of
beat strike (a person or an animal) repeatedly and violently so as to hurt or injure them, typically with an implement such as a club or whip
become begin to be
bed a piece of furniture for sleep or rest, typically a framework with a mattress
beg ask someone earnestly or humbly for something
begin perform or undergo the first part of (an action or activity)
behead cut off the head of (someone), especially as a form of execution
believe accept that (something) is true, especially without proof
belittle dismiss (someone or something) as unimportant
belong be the property of
belt a strip of leather or other material worn, typically round the waist, to support or hold in clothes or to carry weapons
benefit an advantage or profit gained from something
best of the most excellent or desirable type or quality
bet risk a sum of money or valued item against someone else
better more desirable, satisfactory, or effective
beware be cautious and alert to risks or dangers
bicycle a vehicle consisting of two wheels held in a frame one behind the other, propelled by pedals and steered with handlebars attached to the front wheel
bid offer (a certain price) for something, especially at an auction
big of considerable size or extent
bike a bicycle or motorcycle
bill a printed or written statement of the money owed for goods or services
bin throw (something) away by putting it in a bin
bind tie or fasten (something) tightly together
bird a warm
bisect divide into two parts
bite (of a person or animal) use the teeth to cut into or through something
black of the very darkest colour owing to the absence of or complete absorption of light
bleed lose blood from the body as a result of injury or illness
blend mix (a substance) with another substance so that they combine together
blind unable to see because of injury, disease, or a congenital condition
block a large solid piece of hard material, especially rock, stone, or wood, typically with flat surfaces on each side
blood the red liquid that circulates in the arteries and veins of humans and other vertebrate animals, carrying oxygen to and carbon dioxide from the tissues of the body
blunder a stupid or careless mistake
board a long, thin, flat piece of wood or other hard material, used for floors or other building purposes
bob make a quick, short movement up and down
bomb a container filled with explosive or incendiary material, designed to explode on impact or when detonated by a timing, proximity, or remote
bone any of the pieces of hard whitish tissue making up the skeleton in humans and other vertebrates
book a written or printed work consisting of pages glued or sewn together along one side and bound in covers
boomerang (of a plan or action) recoil on the originator
boot a sturdy item of footwear covering the foot and ankle, and sometimes also the lower leg
bore make (a hole) in something with a tool or by digging
born existing as a result of birth
borrow take and use (something belonging to someone else) with the intention of returning it
boss a person who is in charge of a worker, group, or organization
bother take the trouble to do something
bottom the lowest point or part of something
bound walk or run with leaping strides
box a container with a flat base and sides, typically square or rectangular and having a lid
brace a device fitted to something, in particular a weak or injured part of the body, to give support
bracket each of a pair of marks ( ) 
braid threads of silk, cotton, or other material woven into a decorative band for edging or trimming garments
brain an organ of soft nervous tissue contained in the skull of vertebrates, functioning as the coordinating centre of sensation and intellectual and nervous activity
;========================================================
mutantGOD-
Posts: 9
Joined: 22 Oct 2022, 09:31

Re: copy google define definitions and write them in a text file

Post by mutantGOD- » 23 Oct 2022, 10:09

garry wrote:
23 Oct 2022, 08:32
yes , it worked ...

Code: Select all

bare
bargain
bark
bat
batch
bath
batter
be
beam
bear
beat
become
bed
beg
begin
behead
believe
belittle
belong
belt
benefit
best
bet
better
beware
bicycle
bid
big
bike
bill
bin
bind
bird
bisect
bite
black
bleed
blend
blind
block
blood
blunder
board
bob
bomb
bone
book
boomerang
boot
bore
born
borrow
boss
bother
bottom
bound
box
brace
bracket
braid
brain
;=====================================================
bare (of a person or part of the body) not clothed or covered
bargain an agreement between two or more people or groups as to what each will do for the other
bark the sharp explosive cry of a dog, fox, or seal
bat an implement with a handle and a solid surface, typically of wood, used for hitting the ball in games such as cricket, baseball, and table tennis
batch a quantity or consignment of goods produced at one time
bath a large container for water, used for immersing and washing the body
batter strike repeatedly with hard blows
be exist
beam a long, sturdy piece of squared timber or metal used to support the roof or floor of a building
bear carry the weight of
beat strike (a person or an animal) repeatedly and violently so as to hurt or injure them, typically with an implement such as a club or whip
become begin to be
bed a piece of furniture for sleep or rest, typically a framework with a mattress
beg ask someone earnestly or humbly for something
begin perform or undergo the first part of (an action or activity)
behead cut off the head of (someone), especially as a form of execution
believe accept that (something) is true, especially without proof
belittle dismiss (someone or something) as unimportant
belong be the property of
belt a strip of leather or other material worn, typically round the waist, to support or hold in clothes or to carry weapons
benefit an advantage or profit gained from something
best of the most excellent or desirable type or quality
bet risk a sum of money or valued item against someone else
better more desirable, satisfactory, or effective
beware be cautious and alert to risks or dangers
bicycle a vehicle consisting of two wheels held in a frame one behind the other, propelled by pedals and steered with handlebars attached to the front wheel
bid offer (a certain price) for something, especially at an auction
big of considerable size or extent
bike a bicycle or motorcycle
bill a printed or written statement of the money owed for goods or services
bin throw (something) away by putting it in a bin
bind tie or fasten (something) tightly together
bird a warm
bisect divide into two parts
bite (of a person or animal) use the teeth to cut into or through something
black of the very darkest colour owing to the absence of or complete absorption of light
bleed lose blood from the body as a result of injury or illness
blend mix (a substance) with another substance so that they combine together
blind unable to see because of injury, disease, or a congenital condition
block a large solid piece of hard material, especially rock, stone, or wood, typically with flat surfaces on each side
blood the red liquid that circulates in the arteries and veins of humans and other vertebrate animals, carrying oxygen to and carbon dioxide from the tissues of the body
blunder a stupid or careless mistake
board a long, thin, flat piece of wood or other hard material, used for floors or other building purposes
bob make a quick, short movement up and down
bomb a container filled with explosive or incendiary material, designed to explode on impact or when detonated by a timing, proximity, or remote
bone any of the pieces of hard whitish tissue making up the skeleton in humans and other vertebrates
book a written or printed work consisting of pages glued or sewn together along one side and bound in covers
boomerang (of a plan or action) recoil on the originator
boot a sturdy item of footwear covering the foot and ankle, and sometimes also the lower leg
bore make (a hole) in something with a tool or by digging
born existing as a result of birth
borrow take and use (something belonging to someone else) with the intention of returning it
boss a person who is in charge of a worker, group, or organization
bother take the trouble to do something
bottom the lowest point or part of something
bound walk or run with leaping strides
box a container with a flat base and sides, typically square or rectangular and having a lid
brace a device fitted to something, in particular a weak or injured part of the body, to give support
bracket each of a pair of marks ( ) 
braid threads of silk, cotton, or other material woven into a decorative band for edging or trimming garments
brain an organ of soft nervous tissue contained in the skull of vertebrates, functioning as the coordinating centre of sensation and intellectual and nervous activity
;========================================================
it doesn`t work on my pc, i switched os twice

can you create like 4 files for me if it works for you
to define.rar
(8.71 KiB) Downloaded 14 times
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: copy google define definitions and write them in a text file

Post by garry » 23 Oct 2022, 13:16

Now I had no success , get error from google if use a loop with many words
maybe try with few words ....

to see this error , don't delete the html-file
FileRead, html, %file%
;FileDelete, %file%

Code: Select all

Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests, and not a robot. 
Why did this happen?

This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the Terms of Service. 
The block will expire shortly after those requests stop. 
In the meantime, solving the above CAPTCHA will let you continue to use our services.

This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests. 
If you share your network connection, ask your administrator for help — a different computer using the same IP address may be responsible.
Learn more

Sometimes you may be asked to solve the CAPTCHA if you are using advanced terms that robots are known to use, or sending requests very quickly.
IP address: 1210:52cd: xxxx
Time: 2022-10-23T18:14:07Z
URL: https://www.google.com/search?q=define+allow
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: copy google define definitions and write them in a text file

Post by mikeyww » 23 Oct 2022, 17:36

I've had this happen as well, at times, with Google. The APIs, when available, are likely to be more reliable and consistent.
Post Reply

Return to “Ask for Help (v1)”