Jump to content

Read text from site.


Jack023
 Share

Recommended Posts

Hey all,

I'm trying to read a text from my site.

Only text there can be is On or Off

and tryed to make a if statement with no luck :(

site=: http://jackclania.netai.net/test2.php

#include <IE.au3>

$i = 1
Do
    sleep(3000)
    $oIE = _IECreate("http://jackclania.netai.net/test2.php", "", 0)
    $sHTML = _IEBodyReadText($oIE)
    MsgBox(0, "status", "status = " & $sHTML)
    If _IEBodyReadText($oIE) = "on" then
    Do
        MsgBox(0, "ON", "status = ON")
        $oIE = _IECreate("http://jackclania.netai.net/test2.php", "", 0)
        $sHTML = _IEBodyReadText($oIE)
    Until $sHTML = "off"
ElseIf _IEBodyReadText($oIE) = "on" then
    Do
    MsgBox(0, "OFF", "status = OFF")
    $oIE = _IECreate("http://jackclania.netai.net/test2.php", "", 0)
    $sHTML = _IEBodyReadText($oIE)
    ProcessClose("iexplore.exe")
    MsgBox(0, "ON", "status = on")
    Until $sHTML = "on"
EndIf
Until $i = 0

Thanks in advance :))

Link to comment
Share on other sites

Maybe...

 
#include <IE.au3>
 
$oIE = _IECreate("http://jackclania.netai.net/test2.php");, "", 0)
 
HotKeySet("{ESC}", "Terminate")
 
While 1
Sleep(3000)
 
$sHTML = _IEBodyReadText($oIE)
MsgBox(0, "status", "status = *" & $sHTML & "*"); note there is a return in here
 
If StringInStr($sHTML, "on") Then
MsgBox(0, "ON", "status = ON")
_IENavigate($oIE, "http://jackclania.netai.net/test2.php?set=off")
 
Else
MsgBox(0, "OFF", "status = OFF")
_IENavigate($oIE, "http://jackclania.netai.net/test2.php?set=on")
 
EndIf
 
WEnd
 
Func Terminate()
_IEQuit($oIE)
Exit 0
EndFunc   ;==>Terminate
 
 

NEWHeader1.png

Link to comment
Share on other sites

works good, only the  _ienavigate was not needed.

Only i want that after it checked like if it's on, it keeps checking it untill its OFF and then restart the previous loop again.

It's now like this:

#include <IE.au3>

$oIE = _IECreate("http://jackclania.netai.net/test2.php", "", 0);, "", 0)

HotKeySet("{ESC}", "Terminate")

While 1
sleep(3000)
$sHTML = _IEBodyReadText($oIE)
MsgBox(0, "status", "status = *" & $sHTML & "*"); note there is a return in here

If StringInStr($sHTML, "on") Then
MsgBox(0, "ON", "status = ON")
;~ _IENavigate($oIE, "http://jackclania.netai.net/test2.php?set=off")

Else
MsgBox(0, "OFF", "status = OFF")
;~ _IENavigate($oIE, "http://jackclania.netai.net/test2.php?set=on")

EndIf

WEnd

Func Terminate()
_IEQuit($oIE)
Exit 0
EndFunc   ;==>Terminate
Edited by Jack023
Link to comment
Share on other sites

#include "WinHttp.au3"

$text = 0 // when i removed this it gave a error.

    Opt("MustDeclareVars", 1)

    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen()
    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, "http://jackclania.netai.net/status")

$text = _WinHttpSimpleRequest($hConnect, "GET", "http://jackclania.netai.net/status")
MsgBox(0, "", $text)

    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

but what i need is read if it's on or off on the page http://jackclania.netai.net/status

Link to comment
Share on other sites

There are several ways

$url = "http://jackclania.netai.net/status"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
; or :
; $oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", $url, 0)
$oHTTP.Send()
Local $txt = $oHTTP.Responsetext 
$oHTTP = 0
Msgbox(0,"", $txt)

; else
Msgbox(0,"", BinaryToString(InetRead($url, 1)))

or _InetGetSource, etc

Link to comment
Share on other sites

  • Moderators

Jack023,

Threads merged - please stick to just the one at a time in future. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#include "WinHttp.au3"

$text = 0

    Opt("MustDeclareVars", 1)

    ; Initialize and get session handle
    Global $hOpen = _WinHttpOpen()
    ; Get connection handle
    Global $hConnect = _WinHttpConnect($hOpen, "http://jackclania.netai.net/status")

$text = _WinHttpSimpleRequest($hConnect, "GET", "http://jackclania.netai.net/status")
MsgBox(0, "", $text)

    ; Close handles
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

Alright, i heard that i could use winhttp instead of IE.

So i try to read on the page: http://jackclania.netai.net/status if the message is ON or off , it can be both.

I want this in a loop but the script above dont work.

Greets,

Jack

Link to comment
Share on other sites

$url = "http://jackclania.netai.net/status"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
; or :
; $oHTTP = ObjCreate("Microsoft.XMLHTTP")
$oHTTP.Open("GET", $url, 0)
$oHTTP.Send()
Local $txt = $oHTTP.Responsetext 
$oHTTP = 0
Msgbox(0,"", $txt)

; else
Msgbox(0,"", BinaryToString(InetRead($url, 1)))

worked fine for me, thanks !

Does it also work when the pc don't have internet explorer?

Edited by Jack023
Link to comment
Share on other sites

  • Moderators

And as I asked before, you need to clarify what you mean by "don't have internet explorer". Do you mean when the person is using a different browser, or has internet explorer actually been disabled altogether?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Still trying to understand under what circumstance you would have a user in that situation. It takes a lot to disable all web browsers on a Windows machine. My question from post #15 still stands; since you obviously have a specific scenario in mind, have you tried to duplicate it yourself?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...