matthewst Posted July 27, 2006 Share Posted July 27, 2006 I need to monitor a webpage for updates. Once updated I need it to open automatically. The page I'm referring to is internal and doesn't have an rss feed. Can autoit do this? How? Link to comment Share on other sites More sharing options...
Valuater Posted July 27, 2006 Share Posted July 27, 2006 IE Lesson from Welcome to Autoit 1-2-3 ; Read the contents of the body of a webpage and search for a string. If the string is found, replace it ; with a new string and write it back to the webpage. #include <IE.au3> $oIE = _IECreate() _IENavigate($oIE, "http://www.autoitscript.com/") $body = _IEBodyReadHTML($oIE) If StringInStr($body, "automation") Then MsgBox(0, "Success", "The string was found") $newbody = StringReplace($body, "automation", "AUTOMATION - Yeah!") _IEBodyWriteHTML($oIE, $newbody) Else MsgBox(0, "Fail", "The string was NOT found") EndIf Exit this could help alot 8) Link to comment Share on other sites More sharing options...
matthewst Posted July 27, 2006 Author Share Posted July 27, 2006 (edited) I can't use the traditional FileGetTime because I don't have access to the actual file. I can only view it through IE. Any ideas? I was a bit late with the details, sorry about that Valuater. I can't edit the file either. I can only view it through IE. Edited July 27, 2006 by matthewst Link to comment Share on other sites More sharing options...
matthewst Posted July 27, 2006 Author Share Posted July 27, 2006 I'm not sure if it would be better to have autoit take a snapshot of the page every 30 seconds then open the page if there are differences. Or if I should try to have autoit view the source code every 30 seconds then open the page if there are changes. Link to comment Share on other sites More sharing options...
Matthy Posted July 27, 2006 Share Posted July 27, 2006 (edited) Meaby you need to read the body with IE and if somethings chanced in the body then launch the site im not an programmer that can write these things in one sec so sorry hope i helped Edited July 27, 2006 by Matthy Link to comment Share on other sites More sharing options...
matthewst Posted July 27, 2006 Author Share Posted July 27, 2006 That makes sense. I just need to track down IE.au3 Link to comment Share on other sites More sharing options...
matthewst Posted July 27, 2006 Author Share Posted July 27, 2006 Using Penny-Arcade to test and a little of Valuaters script I think I'm on the right track. #include <IE.au3> $oIE = _IECreate() _IENavigate($oIE, "http://www.penny-arcade.com/") $body = _IEBodyReadHTML($oIE) How do I store the results of the IEBodyReadHTML? How do I compare them to a later read? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 27, 2006 Moderators Share Posted July 27, 2006 Something like this should work for you. #include <IE.au3> $sURL = "http://www.penny-arcade.com/" $oIE = _IECreate($sURL) $sHTML = _IEBodyReadHTML($oIE) While WinExists(_IEPropertyGet($oIE, "hwnd")) _IEAction($oIE, "refresh") $sTemp = _IEBodyReadHTML($oIE) If $sTemp <> $sHTML Then ;;; Whatever you want to do here $sHTML = $sTemp EndIf ; Change this to control the time between checks Sleep(5000) WEnd Link to comment Share on other sites More sharing options...
dabus Posted July 27, 2006 Share Posted July 27, 2006 Wouldn't it be faster to check the filesize than checking the whole page? E.g. save the file and look for the size? (Don't know how big this page is and if it just will grow bigger or actually "changes".) Link to comment Share on other sites More sharing options...
sshrum Posted July 27, 2006 Share Posted July 27, 2006 Wouldn't it be faster to check the filesize than checking the whole page? E.g. save the file and look for the size?(Don't know how big this page is and if it just will grow bigger or actually "changes".)He's pulling a webpage...you can't request file sizes from a web server. Yeah, he could save the file local but what if the changes cancel out giving the exact filesize again...it can happen...and does.My whole enchillada suggestion is to capture the entire page and at a user defined interval, repull the page and do a stringinstr compare over the entire thing. Granted, if ANYTHING changes (like a timestamp), this won't work for what you may want (or maybe it will...I'm sadistic like that).My Mexi-taco suggestion is if you know what you want to monitor for, you'll need to parse the page and extact that section and do stringinstring comparisions on that. If it returns false, the content has changed.M2C Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' Â Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 27, 2006 Moderators Share Posted July 27, 2006 This seems to work nicely. #include <IE.au3> Opt("WinTitleMatchMode", 4) $sURL = "http://www.autoitscript.com/forum/index.php?act=idx" $oIE = _IECreate($sURL, 0, 0) $hwnd = _IEPropertyGet($oIE, "hwnd") WinSetState($hwnd, "", @SW_MINIMIZE) _IEAction($oIE, "visible") $sHTML = _IEBodyReadHTML($oIE) While WinExists($hwnd) _IEAction($oIE, "refresh") $sTemp = _IEBodyReadHTML($oIE) If $sTemp <> $sHTML Then MsgBox(0, "", "The page changed!", 2) WinSetState($hwnd, "", @SW_MAXIMIZE) $sHTML = $sTemp EndIf ; Change this to control the time between checks Sleep(5000) WEnd Link to comment Share on other sites More sharing options...
matthewst Posted July 28, 2006 Author Share Posted July 28, 2006 (edited) Big_daddy, your script seems to be refreshing the page. I'm sure there are behind-the-scenes changes but I only need to be made aware of changes if they are "visible". I think sshrum may be on the right track. I can find the sections in HTML that I need to keep tabs on but I'm not sure how to compare just those sections to section reads taken at a later time. I'm experimenting with stringinstr. No luck so far. Does anyone out there already know how to make this work? Edited July 28, 2006 by matthewst Link to comment Share on other sites More sharing options...
matthewst Posted July 28, 2006 Author Share Posted July 28, 2006 I can't seem to figure this out. Any sugestions? Link to comment Share on other sites More sharing options...
sandyd Posted July 28, 2006 Share Posted July 28, 2006 What you need to do is find a unique start point and end point in the text and compare just that part each time. Whats the page your trying to check? and what part specifically? ----[ SandyD ]--- Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 28, 2006 Moderators Share Posted July 28, 2006 I can't seem to figure this out. Any sugestions?My example would work perfectly for this, you just need to change it up a bit. This should give you some idea. Notice how I'm only monitoring the table that has a class of "newslink" (i.e. the top part that says Welcome Back). expandcollapse popup#include <IE.au3> Opt("WinTitleMatchMode", 4) $sURL = "http://www.autoitscript.com/forum/index.php?act=idx" $oIE = _IECreate($sURL, 0, 0) $hwnd = _IEPropertyGet($oIE, "hwnd") WinSetState($hwnd, "", @SW_MINIMIZE) _IEAction($oIE, "visible") $sHTML = _GetNewsTable($oIE) If @error Then MsgBox(48, "Error", "Unable to find specified table.") Exit EndIf While WinExists($hwnd) _IEAction($oIE, "refresh") $sTemp = _GetNewsTable($oIE) If Not @error Then If $sTemp <> $sHTML Then MsgBox(0, "", "The page changed!", 2) WinSetState($hwnd, "", @SW_MAXIMIZE) $sHTML = $sTemp EndIf EndIf ; Change this to control the time between checks Sleep(5000) WEnd Func _GetNewsTable($o_IE) $o_Tables = _IETableGetCollection($o_IE) For $o_Table In $o_Tables If $o_Table.className == "newslink" Then $s_HTML = $o_Table.innerHTML ExitLoop EndIf Next If $s_HTML == "" Then SetError(1) Return 0 EndIf Return $s_HTML EndFunc ;==>_GetNewsTable Link to comment Share on other sites More sharing options...
matthewst Posted July 28, 2006 Author Share Posted July 28, 2006 (edited) It's an internal webpage, but for an example we could use www.penny-arcade.com. get the title of the current comic store that info in memory somewhere 30 seconds later look at the name of the current comic again if it's the same then nothing happens if it's different then the new name gets stored in memory and the page is opened then repeat the process until i exit the script Any ideas? Edited July 28, 2006 by matthewst Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 28, 2006 Moderators Share Posted July 28, 2006 (edited) It's an internal webpage, but for an example we could use www.penny-arcade.com. get the title of the current comic store that info in memory somewhere 30 seconds later look at the name of the current comic again if it's the same then nothing happens if it's different then the new name gets stored in memory and the page is opened then repeat the process until i exit the script Any ideas?Do I have to write the whole thing for you? The current comic title is "Turnabout", view the webpage source and search for that. Below is the first thing it finds, notice the class name. <div class="title">Turnabout</div> Now reference my last post and see what you can come up with. p.s. You will want to use .innerText instead of .innerHTML Edited July 28, 2006 by big_daddy Link to comment Share on other sites More sharing options...
matthewst Posted July 28, 2006 Author Share Posted July 28, 2006 (edited) Thanks for all the help. I think were getting close. #include <IE.au3> Opt("WinTitleMatchMode", 4) $s_string ='class="title"' $sURL = "http://www.penny-arcade.com/comic" $oIE = _IECreate($sURL, 0, 0) $hwnd = _IEPropertyGet($oIE, "hwnd") WinSetState($hwnd, "", @SW_MINIMIZE) _IEAction($oIE, "visible") $sHTML = StringInStr(.innerText, $s_string) While WinExists($hwnd) _IEAction($oIE, "refresh") $sTemp = _IEBodyReadHTML($oIE) If $sTemp <> $sHTML Then MsgBox(0, "", "The page changed!", 2) $sHTML = $sTemp EndIf ; Change this to control the time between checks Sleep(5000) WEnd I get an error .innertext is referenced outside a with statment Edited July 28, 2006 by matthewst Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 28, 2006 Moderators Share Posted July 28, 2006 It would actually be more like this: expandcollapse popup#include <IE.au3> Opt("WinTitleMatchMode", 4) _IEErrorHandlerRegister() $sURL = "http://www.penny-arcade.com/" $oIE = _IECreate($sURL, 0, 0) $hwnd = _IEPropertyGet($oIE, "hwnd") WinSetState($hwnd, "", @SW_MINIMIZE) _IEAction($oIE, "visible") $sText = _GetComicTitle($oIE) If @error Then MsgBox(48, "Error", "Unable to find specified element.") Exit EndIf While WinExists($hwnd) _IEAction($oIE, "refresh") $sTemp = _GetComicTitle($oIE) If Not @error Then If $sTemp <> $sText Then MsgBox(0, "", "The page changed!", 2) WinSetState($hwnd, "", @SW_MAXIMIZE) $sText = $sTemp EndIf EndIf ; Change this to control the time between checks Sleep(5000) WEnd Func _GetComicTitle($o_IE) $s_Text = "" $o_Divs = _IETagNameGetCollection($o_IE, "DIV") For $o_Div In $o_Divs If $o_Div.className == "title" Then $s_Text = $o_Div.innerText ExitLoop EndIf Next If $s_Text == "" Then SetError(1) Return 0 EndIf Return $s_Text EndFunc ;==>_GetComicTitle Link to comment Share on other sites More sharing options...
matthewst Posted July 28, 2006 Author Share Posted July 28, 2006 Thanks everyone for your help. I'm testing and experimenting now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now