AutoHotkey Community

It is currently May 26th, 2012, 10:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: October 26th, 2009, 1:07 am 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2009, 4:47 am 
Offline

Joined: August 22nd, 2009, 11:23 pm
Posts: 294
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,

_________________
Image
"Man's quest for knowledge is an expanding series whose limit is infinity"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2009, 6:16 pm 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
I want to check a specific URL and check and see if that URL contains a specific keyword, or lacks a specific keyword.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2009, 6:38 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
3-4 line script
- UrlDownloadToFile URL
- Fileread file
- use IfInString (InStr, or RegExMatch)
- Done

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2009, 9:31 pm 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
@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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 26th, 2009, 9:43 pm 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
...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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 2:20 am 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
So I download the URL into a file... how do I put that file into one string to use InString? Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 2:35 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
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.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 2:51 am 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
or download directly to a variable using URLdownloadToVar
:wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 3:01 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
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:

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 3:07 am 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 5:59 am 
Offline

Joined: May 13th, 2009, 5:51 pm
Posts: 30
hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
:x
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 6:07 am 
Offline

Joined: June 8th, 2006, 2:41 am
Posts: 285
Lafncow wrote:
hey, d-man, you should be appreciative to those who take the time to help you. (for reference)
:x
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 11:16 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
d-man wrote:
... none of you really helped very much. I figured it out myself.
yeah right :D

Anyway, you learned something so you should be happy

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, Google [Bot], JSLover, Leef_me, patgenn123, rbrtryn, Yahoo [Bot] and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group