Jump to content

Recommended Posts

  • Moderators
Posted

mihaibr and Mechaflash,

Please keep your inputs polite. It is obvious that the OP does not have Engish as his first tongue - but that is no reason to engage in personal insults. :naughty:

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

 

Posted

@Melba23, I’m sorry for that, I know that English is not his native language, but at least he should try to translate what he want to post with Google Translator or any other translator.

Posted (edited)

@Melba23 OP doesn't know explain even in romanian. I know this guy from my forum where was banned for his bad attitude and multi accounts.

ONTOPIC:

#include <IE.au3>

$oIE = _IECreate("http://cleverbot.com/",0,1)
$oInput = _IEGetObjByName($oIE,"stimulus")
$oButton = _IEGetObjById($oIE,"sayit")
_IEFormElementSetValue($oInput,"Hello bot.")
_IEAction($oButton,"click")

Sleep(5000)

; You get the response from 10th table using _IETableGetCollection

_IEQuit($oIE)
Edited by Andreik
  • Moderators
Posted

Andreik,

The same remark goes for you - if you cannot keep it polite, please do not bother to post it. :naughty:

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

 

  • Moderators
Posted

Andreik,

I do not care what anyone has done elsewhere - as long as people have not misbehaved here we treat them with respect. I hope that is that quite clear to everyone reading this thread - and I also do not want to see it anywhere else on the forum either. :naughty:

And that is quite enough off-topic stuff - let us get back to the thread. :)

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

 

Posted

@ mihaibr

@ Andreik

Thank you both for your criticism received from `and count the words and I'll try to post a question than precise and to the point.

I'll be more careful next time I post.

@ Andreik

thanks for help.

@ Melba23

Thanks for ... your logic.

Posted (edited)

Hi incepator,

Welcome to AutoIt. Please note that the forum gods help those who help themselves.

I myself initially struggled with AutoIt and IE but with the assistance of others in the forum I managed. Hopefully I can honor them by helping you.

Please look at the code I wrote below...

#include <IE.au3> ;Comments: always have the IE include
$o_IE = _IECreate("http://www.cleverbot.com/") ;Comments: this will launch IE and navigate to the cleverbot website
_IELoadWait($o_IE) ;Comments: this will hold the script while the page loads and is essential
$o_Form = _IEGetObjById($o_IE, "stimulus") ;Comments: this gets the object reference to the form text box where you would type to cleverbot
$o_Think_About_It = _IEGetObjById($o_IE, "sayit") ;Comments: this is the object reference for the 'Think About It' button. This is the button I've used in the example
$o_Think_For_Me = _IEGetObjById($o_IE, "pass") ;Comments: this is the object reference for the 'Think For Me' button. This is a redundant bit of code but I put it here in case you need to use it
$o_Thoughts_So_Far = _IEGetObjById($o_IE, "log") ;Comments: this is the object reference for the 'Thoughts So Far' button. This is a redundant bit of code but I put it here in case you need to use it
_IEFormElementSetValue($o_Form , "are you a real person?") ;Comments: this gets AutoIt to 'type' the string "are you a real person?" into the form text box
_IEAction($o_Think_About_It, "click") ;Comments: this gets AutoIt to click on the 'Think About It' button but you could use any of the other button objects as given above
Sleep(5000) ;Comments: this pauses the AutoIt script for 5 seconds while cleverbot thinks of an answer. You could use another method but it seems as if the page doesn't reload so I don't think _IELoadWait() will work. I haven't bothered to check and I leave other solutions up to you.
$o_Bot_Response = _IEGetObjById($o_IE, "typArea") ;Comments: this gets the object reference to cleverbot's response
$s_Bot_Response = _IEPropertyGet($o_Bot_Response, "innertext") ;Comments: this 'reads' the text of cleverbot's response and puts it into a string variable
ConsoleWrite($s_Bot_Response & @CRLF) ;Comments: this writes cleverbot's response to the console in SciTE. Of course you could then do whatever you want with the string.

If I were you I would copy and paste the above code into SciTE. Once there press 'F5' to execute the script. You will then notice that AutoIt will launch IE, wait for the CleverBot website to load, write in "are you a real person?", click on the 'Think About It' button and then write the CleverBot response into the console of SciTe. However this solution will only work if you DO NOT have IE9 installed on your PC or are embedding the browswer. For more on that issue search the forums.

So how did I get AutoIt to interact with CleverBot? The secret was identifying the objects and knowing what functions to use to interact with them. Many people here may tell you to use Debug Bar with IE to find the "id" or "name" of the object. I like to use Google Chrome. Do what you like but I explain the steps to get there using Google Chome.

First step was I opened up Google chrome and navigated to http://www.cleverbot.com/ and then just right clicked on the form field and buttons, selected "Inspect Element", right clicked on the highlighted webpage code, selected "Copy as HTML". I then pasted the HTML into Notepad.

This was the result:

Think About It! Button:

<input type="button" style="font: 12px Tahoma, Arial, Sans-serif;;color: 000000;;padding:0px;margin-right:2px;" id="sayit" value="Think About It!" onclick="lCBtn('Say')">

Think For Me! Button:

<input type="button" style="font: 12px Tahoma, Arial, Sans-serif;;color: 000000;;padding:0px;margin-right:2px;" id="pass" value="Think For Me!" onclick="lCBtn('Pass')">

Thoughts So Far Button:

<input type="button" style="font: 12px Tahoma, Arial, Sans-serif;;color: 000000;;padding:0px;margin-right:2px;" id="log" value="Thoughts So Far" onclick="lCBtn('Log')">

Form Field:

<input type="text" x-webkit-speech="" onwebkitspeechchange="lCBtn('Say')" style="font: 12px Tahoma, Arial, Sans-serif;;color: 000000;" id="stimulus" name="stimulus" size="55" autocomplete="off" tabindex="1" onkeypress="return stimulusEvent(event)" onkeyup="return stimulusKeyup(event)">

Bot Response:

<span id="typArea"><span style="font: bold 12px Tahoma, Arial, Sans-serif;;color: 0863BB;">You can be my friend.</span></span>

Once we have the HTML for the objects we will want to interact with, we can look within the HTML for the ID or name embedded in the tag and use that to create an object in AutoIt with the function _IEGetObjById() or with _IEGetObjByName.

With the objects defined we can apply other functions to interact with CleverBot using things like _IEFormElementSetValue(), _IEAction() and _IEPropertyGet().

I think your problem was down to trying to submit the form using _IEFormSubmit() but IMHO it is better to simulate a mouse click on a form button as I have had problems with _IEFormSubmit() in the past. As I've found, automating IE doesn't have one 'correct' way. This is a problem because you will need to experiment with several different methods of interacting with a website to figure out what works. However I think you will find that AutoIt makes up for it with a fantastic community and an easy-to-code forgiving language. Try programming this in C# or Perl and you will have way more lines of code and IMHO the code won't be as elegantly simple.

If you want further pointers check out DaleHohm's excellent tool This also helps when finding IDs, names and index values.

Hopefully you can take what I've given you here and work it out for yourself. If this solves your problem please edit your post to have 'Solved' in its title.

Regards, icu

Edited by icu
Posted

Nice script @icu.

This is my script :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <IE.au3>
#include <String.au3>
#NoTrayIcon
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate(@UserName, 361, 312, -1, -1, -1, $WS_EX_TOOLWINDOW)
$Edit1 = GUICtrlCreateEdit("Chat here...", 0, 0, 361, 289, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
$Input1 = GUICtrlCreateInput("", 0, 288, 361, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Button1 = GUICtrlCreateButton("Button1", 56, 200, 75, 25)
GUICtrlSetState(-1, $GUI_HIDE)
Dim $Form1_AccelTable[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($Form1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
GUICtrlSetData($Edit1,GUICtrlRead($Edit1)&@CRLF&GUICtrlRead($Input1))
GUICtrlSetData($Input1,"")
$oIE = _IECreate("http://cleverbot.com/",0,0,1)
$oInput = _IEGetObjByName($oIE,"stimulus")
$oButton = _IEGetObjById($oIE,"sayit")
_IEFormElementSetValue($oInput,GUICtrlRead($Input1))
_IEAction($oButton,"click")
_IELoadWait($oIE)
Sleep(8000)
;GUICtrlSetData($Edit1,"")
$sHTML = _IEBodyReadHTML($oIE)
_IEQuit($oIE)
$string = _StringBetween($sHTML,'<TABLE border=0 cellSpacing=1 cellPadding=5>','<TD colSpan=3>')
$text1 = StringReplace($string[0],"<TBODY>","")
$text2 = StringReplace($text1,"<TR>","")
$text3 = StringReplace($text2,'TD bgColor=#ffffff height=44 width=300><SPAN style="FONT: 12px Tahoma, Arial, Sans-serif; COLOR: #000000">',"")
$text4 = StringReplace($text3,"</SPAN>","")
$text5 = StringReplace($text4,'<TD bgColor=#ffffff height=44 width=300><SPAN id=typArea><SPAN style="FONT: bold 12px Tahoma, Arial, Sans-serif; COLOR: #0863bb">',"")
$text6 = StringReplace($text5,'<TD bgColor=#ffffff height=44 width=300>',"")
$text7 = StringReplace($text6,'<SPAN style="FONT: 12px Tahoma, Arial, Sans-serif; COLOR: #666666">',"")
$text8 = StringReplace($text7,'</TD></TR>',"")
$text9 = StringReplace($text8,'<SPAN style="FONT: bold 12px Tahoma, Arial, Sans-serif; COLOR: #539eeb">',"")
$text10 = StringReplace($text9,'<SPAN id=typArea></TD></TR>',"")
$text11 = StringReplace($text10,'<',"")
$text12 = StringReplace($text11,'TABLE border=0 cellSpacing=0 cellPadding=0 height="100%">',"")
$text13 = StringReplace($text12,@CRLF,"")
GUICtrlSetData($Edit1,GUICtrlRead($Edit1)&@CRLF&$text13)
EndSwitch
WEnd

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
×
×
  • Create New...