Jump to content

How to find form names


 Share

Recommended Posts

I thought I knew how to do this, but I cannot seem to get this done correctly...

Every hour, on the hour (12:00 or 1:00 or 8:00 etc.) I want my program to open this website, type in a word and submit the form. However, I cannot seem to get it to find the right box...it says no match found.

The website is:

http://weather.noaa.gov/weather/metar.shtml

And I want it to type my local airport's identifier into the box in the middle of the screen and hit submit.

Looking at the source I found this:

<FORM NAME="textbox" METHOD="post" ACTION="/mgetmetar.php">

<INPUT TYPE="TEXT" NAME="cccc" SIZE="20" ALIGN="MIDDLE"><br>

<INPUT TYPE="SUBMIT" NAME="Submit" VALUE="SUBMIT" ALIGN="MIDDLE">

So I was thinking that the form is called textbox and the actual textbox itself was called cccc and the button was called submit. But I'm failing to get my code correct for this...

On a side note, something that would be nice too is if it would just display a msgbox with the results and close the page. For example, type in KDEN to the "cccc" box and view the results.

If I could get the stuff after "The observation is: " displayed in a msgbox, that would be great! Otherwise, it's not really a big deal...I guess the webpage would be fine. It will just suck when I get home from a 6 hour shift and I have 6 webpages open...I guess I could just put a sleep(350000) or something in there and then close the page, but it would be nice to use a timeout on a msgbox.

Any idea how to do either one of those two things?

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

This works fine for me:

#include <ie.au3>
$oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml")
$oForm = _IEFormGetObjByName ($oIE, "textbox")
$oText = _IEFormElementGetObjByName ($oForm, "cccc")
_IEFormElementSetValue ($oText, "KDEN")
$oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
_IEAction ($oSubmit, "click")
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

No, you can savely remove the o in $oIE and use $IE instead. It's just a name.

But make sure to change all $o into $.

But a

ConsoleWrite(@error)
after the submit and post the result.

I'm using IE 7 on Windows XP.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This works fine for me and displays the result in a MSGBOX:

#include <ie.au3>
$oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml")
$oForm = _IEFormGetObjByName($oIE, "textbox")
$oText = _IEFormElementGetObjByName($oForm, "cccc")
_IEFormElementSetValue($oText, "KDEN")
$oSubmit = _IEFormElementGetObjByName($oForm, "Submit")
_IEAction($oSubmit, "click")
_IELoadWait($oIE)
$sBodyText = _IEBodyReadText($oIE)
$sResult = StringMid($sBodyText, StringInStr($sBodyText, "KDEN ", 0, 2))
$sResult = StringLeft($sResult, StringInStr($sResult, @CRLF) - 2)
_IEQuit($oIE)
MsgBox(0, "", "Result For KDEN: " & $sResult)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I managed to get the results I wanted using stringsplit. Not sure if this was the cleanest way to do it or not, but it works, lol

#Include <IE.au3>

While 1 
    If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then
        $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml")
        $oForm = _IEFormGetObjByName ($oIE, "textbox")
        $oText = _IEFormElementGetObjByName ($oForm, "cccc")
        _IEFormElementSetValue ($oText, "KDEN")
        $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
        _IEAction ($oSubmit, "click")
        _IELoadWait($oIE)
        $MyText0 = _IEBodyReadText($oIE)
        $MyText1 = StringSplit($MyText0,"The observation is:",1)
        $MyText = StringSplit($MyText1[2],"US",1)
        MsgBox(0,"METAR",$MyText[1],60)
        WinClose("METAR Data Access")
    EndIf
WEnd

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

Glad it works!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I managed to get the results I wanted using stringsplit. Not sure if this was the cleanest way to do it or not, but it works, lol

I didn't post this, because water beat me to this, but I did it with a regexp:

#include<IE.au3>
Local $oIE, $oForm, $oInput, $oButton
Local $aText, $sText, $sSearch

$sSearch = StringUpper(InputBox("Observation search","Please enter your search term","KDEN"))
$oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
$oForm = _IEFormGetObjByName($oIE,"textbox")
$oInput = _IEFormElementGetObjByName($oForm,"cccc")
_IEFormElementSetValue($oInput,$sSearch)
$oButton = _IEFormElementGetObjByName($oForm,"Submit")
_IEAction($oButton,"click")
_IELoadWait($oIE,100,10000)
$sText = _IEBodyReadText($oIE)
_IEQuit($oIE)
$aText = StringRegExp($sText,"(\d{4}/\d{2}/\d{2} \d{2}:\d{2} " & $sSearch & " .*)",1)
If IsArray($aText) Then
    MsgBox(0,"The observation is:",$aText[0])
Else
    MsgBox(0,"Nothing to see here","Move along sir")
EndIf
Exit

Edit:

You can also support multiple searches at once like this:

#include<IE.au3>
Local $oIE, $oForm, $oInput, $oButton
Local $aText, $sText, $sSearch

$sSearch = StringUpper(InputBox("Observation search","Please enter your search term","KDEN KDSM FAKE"))
If Not $sSearch Then Exit
$aSearch = StringSplit($sSearch," ")
$oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
$oForm = _IEFormGetObjByName($oIE,"textbox")
$oInput = _IEFormElementGetObjByName($oForm,"cccc")
_IEFormElementSetValue($oInput,$sSearch)
$oButton = _IEFormElementGetObjByName($oForm,"Submit")
_IEAction($oButton,"click")
_IELoadWait($oIE,100,10000)
$sText = _IEBodyReadText($oIE)
_IEQuit($oIE)
For $i = 1 To $aSearch[0]
    $aText = StringRegExp($sText,"(\d{4}/\d{2}/\d{2} \d{2}:\d{2} " & $aSearch[$i] & " .*)",1)
    If IsArray($aText) Then
        MsgBox(0,"The observation for " & $aSearch[$i] & " is:",$aText[0])
    Else
        MsgBox(0,"No observation found for " & $aSearch[$i],"Move along sir")
    EndIf
Next
Exit
Edited by Tvern
Link to comment
Share on other sites

It can be IE free too:

#include "WinHttp.au3"

Global $sICAOLocation = "KDEN"

; Initialize and get session handle
Global $hOpen = _WinHttpOpen()
; Get connection handle
Global $hConnect = _WinHttpConnect($hOpen, "weather.noaa.gov")
; Fill form on that page
Global $sRead = _WinHttpSimpleFormFill($hConnect, "weather/metar.shtml", "name:textbox", "name:cccc", $sICAOLocation)
; Close connection handle
_WinHttpCloseHandle($hConnect)
; See what's returned
;ConsoleWrite($sRead & @CRLF)

Global $aRead = StringRegExp($sRead, ">(.*?\v\Q" & $sICAOLocation & "\E.*?)\v+<", 3)
If @error Then
    MsgBox(48 + 262144, "Meh...", "Nothing!")
Else
    ConsoleWrite($aRead[0] & @CRLF)
    MsgBox(64 + 262144, "Done!", "Result for " & $sICAOLocation & ": " & @CRLF & $aRead[0])
EndIf

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I managed to get the results I wanted using stringsplit. Not sure if this was the cleanest way to do it or not, but it works, lol

#Include <IE.au3>

While 1 
    If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then
        $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml")
        $oForm = _IEFormGetObjByName ($oIE, "textbox")
        $oText = _IEFormElementGetObjByName ($oForm, "cccc")
        _IEFormElementSetValue ($oText, "KDEN")
        $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
        _IEAction ($oSubmit, "click")
        _IELoadWait($oIE)
        $MyText0 = _IEBodyReadText($oIE)
        $MyText1 = StringSplit($MyText0,"The observation is:",1)
        $MyText = StringSplit($MyText1[2],"US",1)
        MsgBox(0,"METAR",$MyText[1],60)
        WinClose("METAR Data Access")
    EndIf
WEnd

Replace If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then

by If @MIN = "00" And @SEC= "00 Then

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Replace If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then

by If @MIN = "00" And @SEC= "00 Then

I wouldn't do that. If you miss the whole hour (e.g. 08:00:00) by one second the script will wait for another hour.

I will come up with a solution after dinner ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I wouldn't do that. If you miss the whole hour (e.g. 08:00:00) by one second the script will wait for another hour.

I will come up with a solution after dinner ;)

You're right but if you remove @Sec, script can be run several times until min = 1

I believed you want one start by hour !

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

I would do something like this:

$iHourProcessed = ""
While 1
    If @HOUR <> $iHourProcessed Then
        $iHourProcessed = @HOUR
        _ProcessWebSite()
    EndIf
    Sleep(60*1000) ; Sleep 60 Seconds
WEnd

Func _ProcessWebSite()
    ConsoleWrite("Function " & @HOUR & @CRLF)
EndFunc

In this example processing starts immediately after you start the script. Then the hour is checked every minute and processing starts if @HOUR has changed.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I would do something like this:

$iHourProcessed = ""
While 1
    If @HOUR <> $iHourProcessed Then
        $iHourProcessed = @HOUR
        _ProcessWebSite()
    EndIf
    Sleep(1000) ; Sleep 1 Minute
WEnd

Func _ProcessWebSite()
    ConsoleWrite("Function " & @HOUR & @CRLF)
EndFunc

In this example processing starts immediately after you start the script. Then the hour is checked every minute and processing starts if @HOUR has changed.

Sleep(1000) = Sleep 1 Minute ! Posted Image

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Oops ;)

Changed my code in the previous post.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I didn't really like having to write all the hours out, but I thought that was the best (most stable) way to write the code so that's what I did. I don't understand the code above (post #13) lol...

Anyway, I fixed a few other things that just make the script run better:

I put a var in there to check if it's already run that hour or not so that when I close the msgbox it doesn't re-open XD

I also made the IE run hidden since I don't really want to see that, I just want the information displayed

And I fixed the timeout on my msgbox so that it will close about every hour (a little less just to be safe) so the code gets the next hour's info

Tested it overnight and liked the results so I think I'm done with it (unless I can find a better way to do the @HOUR stuff that is)

#Include <IE.au3>

Global $DoLoop = 1

While 1 
    If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then
        If $DoLoop = 1 Then
            $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
            $oForm = _IEFormGetObjByName ($oIE, "textbox")
            $oText = _IEFormElementGetObjByName ($oForm, "cccc")
            _IEFormElementSetValue ($oText, "KDEN")
            $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
            _IEAction ($oSubmit, "click")
            _IELoadWait($oIE)
            $MyText0 = _IEBodyReadText($oIE)
            $MyText1 = StringSplit($MyText0,"The observation is:",1)
            $MyText = StringSplit($MyText1[2],"US",1)
            WinClose("METAR Data Access")
            $Box = MsgBox(0,"METAR",$MyText[1],3500)
            If $Box = 1 Then $DoLoop = 0
        EndIf
    EndIf
WEnd

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

I don't understand the code above (post #13) lol...

The code does exactly the same as you do with your code (you set a flag, I store the hour). It stores the hour when it last processed the web site in the variable $iHourProcessed. The next time the script processes the web site again is when the variable @HOUR changes. To cut down CPU usage it uses a sleep of 1 minute in the loop. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Okay, I see. I made a short code to just test it and I think I like that better. Shorter and it also runs upon initial load (I put the file in my startup) so thats nice

I think I added that correctly...here's the updated code:

#Include <IE.au3>

Global $DoLoop = 1
Dim $CurHour

While 1 
    If $CurHour <> @HOUR Then
        $CurHour = @HOUR
        If $DoLoop = 1 Then
            $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
            $oForm = _IEFormGetObjByName ($oIE, "textbox")
            $oText = _IEFormElementGetObjByName ($oForm, "cccc")
            _IEFormElementSetValue ($oText, "KDEN")
            $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
            _IEAction ($oSubmit, "click")
            _IELoadWait($oIE)
            $MyText0 = _IEBodyReadText($oIE)
            $MyText1 = StringSplit($MyText0,"The observation is:",1)
            $MyText = StringSplit($MyText1[2],"US",1)
            WinClose("METAR Data Access")
            $Box = MsgBox(0,"METAR",$MyText[1],300)
            If $Box = 1 Then $DoLoop = 0
        EndIf
    EndIf
WEnd

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

There are a few problems with your code:

1. There is no Sleep

2. because the msgbox always returns 1, doloop will be set to 0, meaning it will only run once, even though the script stays active

3. IE isn't closed properly

4. Usage of Dim and undeclared vars, but that's not realy an error, but just "something to avoid"

here is how I would modify your script:

#Include <IE.au3>

Global $CurHour
Global $oIE, $oForm, $oText, $oSubmit
Global $aText, $sText

While 1
    If $CurHour <> @HOUR Then
    $CurHour = @HOUR
        $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
        $oForm = _IEFormGetObjByName ($oIE, "textbox")
        $oText = _IEFormElementGetObjByName ($oForm, "cccc")
        _IEFormElementSetValue ($oText, "KDEN")
        $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
        _IEAction ($oSubmit, "click")
        _IELoadWait($oIE)
        $sText = _IEBodyReadText($oIE)
        $aText = StringSplit($sText,"The observation is:",1)
        $aText = StringSplit($aText[2],"US",1)
        _IEQuit($oIE) ;proper way to close IE
        MsgBox(0,"METAR",$aText[1],300)
    EndIf
    Sleep(60*1000) ; Can be as short as 10 ms, But you need a sleep, otherwise it will use 100% CPU
WEnd

Although I would go with the winhttp option all together:

#include "WinHttp.au3"

Global $sICAOLocation = "KDEN"
Global $aRead, $sRead
Global $hOpen, $hConnect
Global $CurHour

While 1
    If $CurHour <> @HOUR Then
    $CurHour = @HOUR
        $hOpen = _WinHttpOpen() ;you could take this (and the corrosponding close) out of the loop, but I don't think it's supposed to sit opened for a long time if not used.
        $hConnect = _WinHttpConnect($hOpen, "weather.noaa.gov") ;same as above.
        $sRead = _WinHttpSimpleFormFill($hConnect, "weather/metar.shtml", "name:textbox", "name:cccc", $sICAOLocation)
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        $aRead = StringRegExp($sRead, ">(.*?\v\Q" & $sICAOLocation & "\E.*?)\v+<", 3)
        If @error Then
            MsgBox(48 + 262144, "Meh...", "Nothing!")
        Else
            ConsoleWrite($aRead[0] & @CRLF)
            MsgBox(64 + 262144, "Result for " & $sICAOLocation & ": ",$aRead[0])
        EndIf
    EndIf
    Sleep(60*1000)
WEnd

(Brilliant UDF trancexx!)

I know you've dropped the If @HOUR = "00" OR "01".... part, but for future reference: every part of a statement like that has to be a complete logical expression:

If @HOUR = "00" Or "01" Or "02" Then;...
;means the same as:
If @HOUR = "00" OR True Or True Then;...

;you need to write it out like:
If @HOUR = "00" Or @HOUR = "01" Or @HOUR = "02" Then;...

;In this case a switch statement would have made more sense:
Switch @HOUR
    Case "00", "01", "02"
        ;...
EndSwitch

Link to comment
Share on other sites

Tvern, I noticed all of those things after I posted that, haha. Got so worked up in fixing one thing that I forgot about other problems I was causing, haha. Anyway, I finally got everything put together and it's working great (and I mean it this time).

I do feel like an idiot though...

If @HOUR = "00" OR "01" OR "02" OR "03" OR "04" OR "05" OR "06" OR "07" OR "08" OR "09" OR "10" OR "11" OR "12" OR "13" OR "14" OR "15" OR "16" OR "17" OR "18" OR "19" OR "20" OR "21" OR "22" OR "23" And @MIN = "00" Then

is the same as

If @MIN = "00"

lol...much simpler and means the same thing XD

So I changed that and fixed the IE not closing thing. Never knew you had to do Quit...I thought it would just close and that meant is was quitting, haha.

Added the sleep back in once I noticed it was taking like 97% of my CPU, rofl.

Fixed the run-once error due to my variable

I also included a short test to copy itself to startup if it wasn't running from there. Makes it easier for me (compile to desktop and then just run it)

Here's the full script:

#Include <IE.au3>

Global $Startup = "C:\Users\Justin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\METAR.exe"

If @ScriptFullPath <> $Startup Then
    FileCopy(@ScriptFullPath,$Startup,1)
    Run($Startup)
    FileDelete(@ScriptFullPath)
EndIf

While 1 
    If @MIN = "00" Then
        $oIE = _IECreate("http://weather.noaa.gov/weather/metar.shtml",0,0)
        $oForm = _IEFormGetObjByName ($oIE, "textbox")
        $oText = _IEFormElementGetObjByName ($oForm, "cccc")
        _IEFormElementSetValue ($oText, "KDEN")
        $oSubmit = _IEFormElementGetObjByName ($oForm, "Submit")
        _IEAction ($oSubmit, "click")
        _IELoadWait($oIE)
        $MyText0 = _IEBodyReadText($oIE)
        $MyText1 = StringSplit($MyText0,"The observation is:",1)
        $MyText = StringSplit($MyText1[2],"US",1)
        _IEQuit($oIE)
        $Box = MsgBox(0,"METAR",$MyText[1],120)
        If $Box = 1 Then Sleep(60000)
    Else
        Sleep(60000)    
    EndIf
WEnd
Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...