 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Mon Oct 26, 2009 12:07 am Post subject: help with a script: check website for keyword |
|
|
| Can someone help me with a skeleton script for checking a web page for a certain keyword or lack thereof, every so many minutes? Input minutes, keyword, and negative or positive search. Thanks in advance. |
|
| Back to top |
|
 |
txquestor
Joined: 22 Aug 2009 Posts: 294
|
Posted: Mon Oct 26, 2009 3:47 am Post subject: |
|
|
Not sure this is the type of web page search you need.
You said | Quote: | | checking a web page for a certain keyword or lack thereof |
Do you know the web page? Or do you want to search the internet
for any pages with the search term?
This script does the latter but does not compile the results.
| Code: |
; Run a Google search on any words he had highlighted (if any), script can handle text in any app
; It has some smart analyzation of the highlighted string and can differentiate between a URL
; and just something you'd like to search for (a search query will have a Google Search run on it, in a new window,
; while a URL will be opened in a new window).
SendMode Input
RegRead, OutputVar, HKEY_CLASSES_ROOT, Applications\iexplore.exe\shell\open\command ; C:\ProgramFiles\Internet Explorer\IEXPLORE.EXE
StringReplace, OutputVar, OutputVar,"
SplitPath, OutputVar,,OutDir,,OutNameNoExt, OutDrive
browser=%OutDir%\%OutNameNoExt%.exe
Menu, Tray, Add
Menu, Tray, add, MinimizeAllWindows
Menu, Tray, add, CloseAllWindows
Menu, Tray, Add, &Reload, ReloadScript
Menu, Tray, Add, Exit, Quit
^!g::
{
BlockInput, on
prevClipboard = %clipboard%
clipboard =
Send, ^c
BlockInput, off
ClipWait, 2
if ErrorLevel = 0
{
searchQuery=%clipboard%
GoSub, GoogleSearch
}
clipboard = %prevClipboard%
return
}
GoogleSearch:
StringReplace, searchQuery, searchQuery, `r`n, %A_Space%, All
Loop
{
noExtraSpaces=1
StringLeft, leftMost, searchQuery, 1
IfInString, leftMost, %A_Space%
{
StringTrimLeft, searchQuery, searchQuery, 1
noExtraSpaces=0
}
StringRight, rightMost, searchQuery, 1
IfInString, rightMost, %A_Space%
{
StringTrimRight, searchQuery, searchQuery, 1
noExtraSpaces=0
}
If (noExtraSpaces=1)
break
}
StringReplace, searchQuery, searchQuery, \, `%5C, All
StringReplace, searchQuery, searchQuery, +, `%2B, All
StringReplace, searchQuery, searchQuery, %A_Space%, +, All
StringReplace, searchQuery, searchQuery, `%, `%25, All
IfInString, searchQuery, .
{
IfInString, searchQuery, +
Run, %browser% http://www.google.com/search?hl=en&q=%searchQuery%
else
Run, %browser% %searchQuery%
}
else
Run, %browser% http://www.google.com/search?hl=en&q=%searchQuery%
return
MinimizeAllWindows:
WinMinimizeAll
return
CloseAllWindows:
WinGet, id, list, , , Program Manager
Loop, %id%
{
StringTrimRight, this_id, id%a_index%, 0
WinGetTitle, this_title, ahk_id %this_id%
winclose,%this_title%
}
Return
ReloadScript:
ToolTip, Reloaded Script!, 700,600
SetTimer, RemoveToolTip, 2000
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
reload
Return
Quit:
ExitApp
return
|
Or did you mean search a single web page & count every instance of seach term?
http://www.autohotkey.com/forum/topic49488.html
I'd suggest you add more details regarding your needs.
There are also various libraries to perform various actions on Web pages.
ie: Com.ahk, IE.ahk, IE7.ahk, iWeb.ahk etc.
Have Fun, _________________
"Man's quest for knowledge is an expanding series whose limit is infinity" |
|
| Back to top |
|
 |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Mon Oct 26, 2009 5:16 pm Post subject: |
|
|
| I want to check a specific URL and check and see if that URL contains a specific keyword, or lacks a specific keyword. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
Lafncow
Joined: 13 May 2009 Posts: 30
|
Posted: Mon Oct 26, 2009 8:31 pm Post subject: |
|
|
@HugoV
I want to agree ...but that doesnt account for html comments or other markup that might yield false positives. To fix that you'd need to turn to some sort of parser to just extract the text. xpath might work by grabbing the body node, then compiling all of its children's text values, then doing the regex match on that result. Sorry to make this all complicated, but just trying to make it iron clad.  |
|
| Back to top |
|
 |
Lafncow
Joined: 13 May 2009 Posts: 30
|
Posted: Mon Oct 26, 2009 8:43 pm Post subject: |
|
|
...OR, to lighten the load you could first do a regex to remove all markup, something like the example in the documentation:
and then do your keyword search.
this should have a lot less overhead than the xpath solution, but on 2nd thought, they still leave you vulnerable to false positives on any embedded CSS or javascript |
|
| Back to top |
|
 |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Tue Oct 27, 2009 1:20 am Post subject: |
|
|
| So I download the URL into a file... how do I put that file into one string to use InString? Thanks. |
|
| Back to top |
|
 |
tidbit
Joined: 09 Mar 2008 Posts: 1807 Location: Minnesota, USA
|
Posted: Tue Oct 27, 2009 1:35 am Post subject: |
|
|
d-man, you skipped step 2. ha.
re-read hugoV's post.
everything hugoV said are AHK commands. not something you do manually. _________________ rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
Even monkeys fall from trees. - Japanese proverb |
|
| Back to top |
|
 |
Lafncow
Joined: 13 May 2009 Posts: 30
|
Posted: Tue Oct 27, 2009 1:51 am Post subject: |
|
|
or download directly to a variable using URLdownloadToVar
 |
|
| Back to top |
|
 |
tidbit
Joined: 09 Mar 2008 Posts: 1807 Location: Minnesota, USA
|
Posted: Tue Oct 27, 2009 2:01 am Post subject: |
|
|
not to sound rude, but I didn't suggest that because he can't even figure out 3-4 steps that were clearly laid out infront of him.
So an external function will probably be to hard/complex/confusing for him.
... again, no offense intended.  _________________ rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
Even monkeys fall from trees. - Japanese proverb |
|
| Back to top |
|
 |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Tue Oct 27, 2009 2:07 am Post subject: |
|
|
I wish people would just post direct help and not all this other stupid stuff.
Anyway, this script seems to be working (for reference):
| Code: | #Persistent
inputbox, url, , Check what website?, ,200, 130
inputbox, key, , Check for what keyword?, ,200, 130
inputbox, pos, , (N)egative or (P)ositive?, ,200, 130
inputbox, tim, , How often to check?, ,200, 130
tim:=tim*60000
settimer, check, %tim%
return
check:
UrlDownloadToFile, %url%, search.txt
FileRead, webpage, search.txt
If pos = p
{
IfInString, webpage, %key%
{
msgbox, *The page now contains your term*
exitapp
}
}
else
{
IfNotInString, webpage, %key%
{
msgbox, *The page now does not contain your term*
exitapp
}
}
return |
|
|
| Back to top |
|
 |
Lafncow
Joined: 13 May 2009 Posts: 30
|
Posted: Tue Oct 27, 2009 4:59 am Post subject: |
|
|
hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
anyway, if you add
| Code: | | webpage := RegExReplace(webpage,"<.+?>","") |
right after your FileRead line, it will remove the HTML so you are only searching the text. |
|
| Back to top |
|
 |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Tue Oct 27, 2009 5:07 am Post subject: |
|
|
| Lafncow wrote: | hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
anyway, if you add
| Code: | | webpage := RegExReplace(webpage,"<.+?>","") |
right after your FileRead line, it will remove the HTML so you are only searching the text. |
I wasn't talking about your post, Lafncow. Your angst is misplaced . I was referring to tidbit, who was quite rude. And honestly, none of you really helped very much. I figured it out myself. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Tue Oct 27, 2009 10:16 am Post subject: |
|
|
| d-man wrote: | | ... none of you really helped very much. I figured it out myself. | yeah right
Anyway, you learned something so you should be happy _________________ AHK Wiki FAQ
TF : Text files & strings lib, TF Forum |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|