AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help with a script: check website for keyword

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
d-man



Joined: 08 Jun 2006
Posts: 285

PostPosted: Mon Oct 26, 2009 12:07 am    Post subject: help with a script: check website for keyword Reply with quote

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
View user's profile Send private message
txquestor



Joined: 22 Aug 2009
Posts: 294

PostPosted: Mon Oct 26, 2009 3:47 am    Post subject: Reply with quote

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
View user's profile Send private message
d-man



Joined: 08 Jun 2006
Posts: 285

PostPosted: Mon Oct 26, 2009 5:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Mon Oct 26, 2009 5:38 pm    Post subject: Reply with quote

3-4 line script
- UrlDownloadToFile URL
- Fileread file
- use IfInString (InStr, or RegExMatch)
- Done
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Lafncow



Joined: 13 May 2009
Posts: 30

PostPosted: Mon Oct 26, 2009 8:31 pm    Post subject: Reply with quote

@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. Smile
Back to top
View user's profile Send private message
Lafncow



Joined: 13 May 2009
Posts: 30

PostPosted: Mon Oct 26, 2009 8:43 pm    Post subject: Reply with quote

...OR, to lighten the load you could first do a regex to remove all markup, something like the example in the documentation:
Code:
<.+?>

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
View user's profile Send private message
d-man



Joined: 08 Jun 2006
Posts: 285

PostPosted: Tue Oct 27, 2009 1:20 am    Post subject: Reply with quote

So I download the URL into a file... how do I put that file into one string to use InString? Thanks.
Back to top
View user's profile Send private message
tidbit



Joined: 09 Mar 2008
Posts: 1807
Location: Minnesota, USA

PostPosted: Tue Oct 27, 2009 1:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Lafncow



Joined: 13 May 2009
Posts: 30

PostPosted: Tue Oct 27, 2009 1:51 am    Post subject: Reply with quote

or download directly to a variable using URLdownloadToVar
Wink
Back to top
View user's profile Send private message
tidbit



Joined: 09 Mar 2008
Posts: 1807
Location: Minnesota, USA

PostPosted: Tue Oct 27, 2009 2:01 am    Post subject: Reply with quote

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. Twisted Evil
_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
Even monkeys fall from trees. - Japanese proverb
Back to top
View user's profile Send private message
d-man



Joined: 08 Jun 2006
Posts: 285

PostPosted: Tue Oct 27, 2009 2:07 am    Post subject: Reply with quote

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
View user's profile Send private message
Lafncow



Joined: 13 May 2009
Posts: 30

PostPosted: Tue Oct 27, 2009 4:59 am    Post subject: Reply with quote

hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
Mad
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
View user's profile Send private message
d-man



Joined: 08 Jun 2006
Posts: 285

PostPosted: Tue Oct 27, 2009 5:07 am    Post subject: Reply with quote

Lafncow wrote:
hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
Mad
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 Wink. 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
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Tue Oct 27, 2009 10:16 am    Post subject: Reply with quote

d-man wrote:
... none of you really helped very much. I figured it out myself.
yeah right Very Happy

Anyway, you learned something so you should be happy
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group