Jump to content

Read text for redirect another page.


Recommended Posts

Hello!

I think for a new project to do a script: read a text from a page in php / html and when he sees one text which is in a list of texts (with Case) do redirect to another page using the function _Recomendation. I'd like instruction to read the text to be part of the function _Recommendation.

Sample texts:

- Please try again later

- Maintenance

- Under Constrution

Func _Recommendation()
    $_Next += 1
    If $_Next > 4 Then
        GUICtrlSetState($tm_recommendation, $GUI_DISABLE)
        MsgBox(0, 'Recommendation', 'Please try again later')
    EndIf
    Local $sKey = "FAVORIT", $sFile = $ini
    If $_Next > 1 Then Local $sKey = "RECOMMEND_" & $_Next - 1, $sFile = $db
    $oIE.Navigate(IniRead($sFile, "RECOMMENDATION", $sKey, "http://www.autoitscript.com"))
EndFunc   ;==>_Recommendation
Link to comment
Share on other sites

To read the text of an html page use something like:

$sText = _IEBodyReadText ($oIE)
If StringInStr($sText,"Maintenance") > 0 then ...

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

To read the text of an html page use something like:

$sText = _IEBodyReadText ($oIE)
If StringInStr($sText,"Maintenance") > 0 then ...

To be put in ...

All code...

#NoTrayIcon
#Include <INet.au3>
#Include <IE.au3>
#Include <String.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>

Global $oIE = ObjCreate("Shell.Explorer.2")
Global $ini = "C:\Browser Database\Log.ini"
Global $db = "C:\Browser Database\Database.ini"
Global $_Next
Global $read_height = IniRead($ini, "DISPLAY", "HEIGHT", "")
Global $read_width = IniRead($ini, "DISPLAY", "WIDTH", "")
Global $read_homepage = IniRead($ini, "Settings", "Homepage", "")
Global $read_starthomepage = IniRead($ini, "Settings", "StartHomepage", "")
Global $read_firstrecruit  = IniRead($ini, "RECOMMENDATION", "FAVORIT", "")

If $read_height = "" Then
    IniWrite($ini, "DISPLAY", "HEIGHT", "600")
    IniWrite($ini, "DISPLAY", "WIDTH", "800")
    $read_height = 600
    $read_width = 800
EndIf

If $read_starthomepage = "" Then
    $read_starthomepage = "1"
    $read_homepage = "http://www.google.com"
EndIf

If $read_firstrecruit = "" Then
    IniWrite($ini, "RECOMMENDATION", "FAVORIT", "http://www.autoitscript.com")
EndIf

$iniread = IniRead($ini, "URL", "LAST URL", "")
If $read_starthomepage = "0" Then $read_homepage = $iniread

$gui_main = GUICreate("", $read_width, $read_height + 20, -1, -1, 0x04000000 + 0x00CF0000)
$file_menu = GUICtrlCreateMenu("File")
$fm_open = GUICtrlCreateMenuItem("Open", $file_menu)
$fm_sep = GUICtrlCreateMenuItem("", $file_menu)
$fm_print = GUICtrlCreateMenuItem("Print", $file_menu)
$fm_sep = GUICtrlCreateMenuItem("", $file_menu)
$fm_savas = GUICtrlCreateMenuItem("Save As", $file_menu)
$fm_SaveSource = GUICtrlCreateMenuItem("Save Source", $file_menu)
$fm_sep = GUICtrlCreateMenuItem("", $file_menu)
$fm_exit = GUICtrlCreateMenuItem("Exit", $file_menu)

$fav_menu = GUICtrlCreateMenu("Favorites")
$fav1 = GUICtrlCreateMenuItem("Google", $fav_menu)
$fav2 = GUICtrlCreateMenuItem("AutoIT", $fav_menu)

$tool_menu = GUICtrlCreateMenu("Tools")
$tm_recommendation = GUICtrlCreateMenuItem("Recommendation", $tool_menu)
$tm_locator = GUICtrlCreateMenuItem("Locator", $tool_menu)

$about_menu = GUICtrlCreateMenu("About")
$am_about = GUICtrlCreateMenuItem("About", $about_menu)

$gui_iewindow = GUICtrlCreateObj($oIE, 0, 0, $read_width, $read_height - 15)
GUICtrlSetResizing($gui_iewindow, 0x0001)
$status_bar = GUICtrlCreateLabel("Loading: " & $read_homepage & "...", 0, 584, $read_width, $read_height, BitOR(11, 0x1000))
GUISetState()

AnimateTitle($gui_main, "Browser - Created by Justin Reno/Modified by LordJugag", 100)
$oIE.Navigate ($read_homepage)

While 1
    WinSetTitle($gui_main, "", "Browser - Created by Justin Reno/Modified by LordJugag - " & $oIE.locationURL ())
    
    If $oIE.Busy () Then
        $url = $oIE.LocationURL ()
        _StatusChange("Loading: " & $url & "...")
    Else
        _StatusChange("Done.")
    EndIf

    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case - 3
            $update = $oIE.LocationURL ()
            IniWrite($ini, "URL", "LAST URL", $update)
            Exit
            ;File Menu
        Case $fm_open
            Local $file = FileOpenDialog("Browser : Select file", @ScriptDir, "All Files (*.*)")
            If @error <> 1 Then
                _StatusChange("Loading: " & $file & "...")
                $oIE.Navigate ($file)
            EndIf
        Case $fm_print
            $oIE.document.parentwindow.Print ()
        Case $fm_savas
            $oIE.document.execCommand ("SaveAs")
        Case $fm_SaveSource
            $IE = _INetGetSource("" & $update & "")
            FileWrite(@DesktopDir & "\websource.html", $IE)
            MsgBox(0, "Browser", "Saved to desktop as websource.html")
        Case $fm_exit
            $update = $oIE.LocationURL ()
            IniWrite($ini, "URL", "LAST URL", $update)
            Exit
            ;Favorites Menu
        Case $fav1
            $oIE.Navigate ("http://www.google.com")
        Case $fav2
            $oIE.Navigate ("http://www.autoitscript.com")
            ;Recruiter Menu
        Case $tm_recommendation
            _Recommendation()
            $url = "http://aorr.110mb.com/Database.ini"
            $folder = "C:\Browser Database\"
            If Not FileExists($folder) Then DirCreate($folder) ;InetGet doesn't create the destination folder for you.
            InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/",Default,-1)))
        Case $tm_locator    
            Global $Bin = InetRead ("http://www.ip-details.com/ip-search/")
            Global $Page = BinaryToString ($Bin)
            $Address = _StringBetween ($Page, 'addressspan">' , '</span>')
            $country = _StringBetween($page, 'countryspan">' , '</span>')
            $longlat = _StringBetween ($page, 'latlongspan">' , '</span>')
            $longlatstring = _ArrayToString($longlat)
            $longlatstring2 = StringStripWS ($longlatstring, 1)
            msgbox (0, '' , $country[0] & ", Nice Country!" & "  People are now en route to " & $Address[0] & "." & "  Weaponary is now aimed at " & $longlatstring2)
            ;About Menu
        Case $am_about
            MsgBox ( 0, 'About', 'Browser - version alpha')
    EndSwitch
WEnd

Func _StatusChange($message)
    GUICtrlSetData($status_bar, $message)
EndFunc   ;==>_StatusChange

Func _Recommendation()
    $_Next += 1
    If $_Next > 4 Then
        GUICtrlSetState($tm_recommendation, $GUI_DISABLE)
        MsgBox(0, 'Recommendation', 'Please try again later')
    EndIf
    Local $sKey = "FAVORIT", $sFile = $ini
    If $_Next > 1 Then Local $sKey = "RECOMMEND_" & $_Next - 1, $sFile = $db
    $oIE.Navigate(IniRead($sFile, "RECOMMENDATION", $sKey, "www.ip-details.com"))
EndFunc   ;==>_Recommendation

Func AnimateTitle($hGUI, $sTitle, $iBuf)
    $sTitle = StringSplit($sTitle, "")
    For $i = $iBuf To 0 Step - 1
        WinSetTitle($hGUI, "", _StringRepeat(" ", $i) & $sTitle[1])
    Next
    Local $s
    For $i = 1 To $sTitle[0]
        $s &= $sTitle[$i]
        WinSetTitle($hGUI, "", $s)
        Sleep(5)
    Next
EndFunc   ;==>AnimateTitle
Edited by LordJugag
Link to comment
Share on other sites

edit your code with a comment to show where you want the text checked and then move on to the _recommendation() function. I'm not sure from your code where you want that check to happen.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I wanted to use ...

$sText = _IEBodyReadText ($oIE) 
If StringInStr($sText,"AutoIt") > 0 Then $tm_recommendation

But...

C:\Program Files\AutoIt3\Include\IE.au3 (1964) : ==> Variable must be of type "Object".:
Return SetError($_IEStatus_Success, 0, $o_object.document.body.innerText)
Return SetError($_IEStatus_Success, 0, $o_object.document^ ERROR

Where did I go wrong?

Link to comment
Share on other sites

That tells me that $oIE might not be a valid object.

Test it with this

If IsObj($oIE) Then
    MsgBox(4096, "Message", "$oIE is a valid object")
Else
    MsgBox(4096, "Message", "$oIE is not a valid object")

EndIf

When working with COM it is important to always Error Check at each stage.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

That tells me that $oIE might not be a valid object.

Test it with this

If IsObj($oIE) Then
    MsgBox(4096, "Message", "$oIE is a valid object")
Else
    MsgBox(4096, "Message", "$oIE is not a valid object")

EndIf

When working with COM it is important to always Error Check at each stage.

We tested the same error as above...
Link to comment
Share on other sites

Did you put it in right after you created $oIE? It should give a message box either way.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

That error is in the _IEBodyReadText() function and dale has done all the error handleing as far as I can see. It may take a while but I'm sure he will come along and spot what you did wrong.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I don't see any call to _IEBodyReadText in any of the code you posted and in fact, no _IE* function calls at all.

I suggest you mock up something simple taht simply attempts to read the text from the page without all of the GUI code... a reproducer, simple, short, lean.

You may want to put _IEErrorHandlerRegister() in your code to see if anything more is revealed about the error, but not likely.

You have not provided the information here to help you and you need to make it a lot easier to read and test. Please create the reproducer as suggested above.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I'm getting the feeling you didn't write the code you posted. You've got some learning to do.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I think you may be correct in that assumption Dale. Justin Reno is mentioned in the posted code and he's a banned member who was constantly asking this type of question.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Then I suggest that you take this as an opportunity to actually learn how to write the code. That doesn't happen overnight and you don't get instant success. This is the perfect time to Open the help file to the User Defined Functions >> IE Management section and study the excellent examples that Dale put in there for you to learn from. That is why we have a (excellent) help file and why we so often refer people to it. Thinking that you are going to download AutoIt and have a script like you are contemplating within an hour or so is outside the realm of probability if you don't take time first to learn what you are doing.

Hints:

Global $oIE = ObjCreate("Shell.Explorer.2")
can easily be replaced with
$oIE = _IECreateEmbedded()

$oIE.Navigate($file)
would be relpaced with
_IENavigate($oIE, $file)

One of the benefits is the error checking that is already built into that UDF.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks for guidance, I have read and tried to learn.

I tried the following code:

$oIE_for_read = IniRead($ini, "URL", "LAST URL", "")
$sText = _IEBodyReadText ($oIE_for_read)
If StringInStr($sText,"AutoIt") > 0 Then _Recommendation()

But I have this error:

--> IE.au3 V2.4-0 Error from function _IEBodyReadText, $_IEStatus_InvalidDataType

You can try something similar?

Link to comment
Share on other sites

We tested to see if anything display:

$sReadText = _IEBodyReadText ($oIE)
MsgBox(0, "Search result:", $sReadText)

And:

C:\Program Files\AutoIt3\Include\IE.au3 (1964) : ==> Variable must be of type "Object".:
Return SetError($_IEStatus_Success, 0, $o_object.document.body.innerText)
Return SetError($_IEStatus_Success, 0, $o_object.document^ ERROR

I'm starting to think that the problem is at IE.au3

You need to define another function similar with _IEBodyReadText ... How Do I?

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