Jump to content

Get text from a website


svkhtn
 Share

Recommended Posts

Hi all,

I just knew AutoIt a couple of days ago. It is amazing. A big thank you to the developing team !!!

I tried to use AutoIt to capture the content text in the floating chatroom of http://www.gabbly.com

However, when I tried to use both WinGetText and ControlGetText, both just returned the link (not the content).

I am a newbie to AutoIt. Could anyone please help or point me to the right direction that I can capture the text from that chatroom?

I also tried FindClassesByText. It showed there are "ComboBoxEx321" and "Edit1" in the gabbly.com. I tried to pass each of these parameters to the ControlGetText, but both returned just the links.

Many thanks,

SV

PS. My intention is to use AutoIt to check the content & chatters silently. Whenever, a certain nickname comes in, it will notify me.

Link to comment
Share on other sites

  • Moderators

This will return the current chat history to the console. This should at least get you on the right track for accomplishing what you are wanting.

#include <IE.au3>

_IEErrorHandlerRegister()

$sURL = "http://www.gabbly.com/"
$oIE = _IECreate($sURL)
$oFrame = _IEFrameGetObjByName($oIE, "mainGabblyFrame")
_IELoadWait($oFrame)
$oDiv = _IEGetObjByName($oFrame, "gabblyChatHistoryDiv")
ConsoleWrite($oDiv.innerText & @CR)
Link to comment
Share on other sites

Hi,

I just installed IE Developer Toolbar and used the DOM explorer. It showed the names of elements of the site.

Now I can grab the contents of gabblyChatHistoryDiv and gabblyPresenceListDiv. They are DIV objects.

However, I tried the same way to get the innerText of gabblyNicknameTextField (i.e. the nickname field). It returned nothing. I noticed that the type of gabblyNicknameTextField is INPUT.

How can I get/set the text from/to that object?

By the way, can the method be used for gabblyMsgInputField (the textbox to type in your chat content) which on IE Dev Tool it shows as TEXTAREA ?

Many thanks!

PS. I am just a newbie. Sorry if the questions are so basic. I tried to read the help file on _IE commands and searched the forum but I haven't got any clue yet.

Edited by svkhtn
Link to comment
Share on other sites

Take a look at _IEFormElementSetValue() and _IEFormElementGetValue()

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

Another question:

After updating the value of the text value of gabblyMsgInputField with _IEFormElementSetValue() (thanks Dale again!), I would like to send the "Enter" key right after that.

I had a look at _IEAction, but it seems there is no "Enter" key action there. The "click" action didn't do my intended job.

The Send command just sends to the current window. There is no parameter to pass an object for the send command.

Could you please point me to the right command?

Many thanks!

Link to comment
Share on other sites

  • Moderators

I just successfully sent a message with this.

#include <IE.au3>

_IEErrorHandlerRegister()

$sNickname = "YourNickname"
$sMessage = "This is a test message"

$sURL = "http://www.gabbly.com/"
$oIE = _IECreate($sURL)
$hwnd = _IEPropertyGet($oIE, "hwnd")
$oFrame = _IEFrameGetObjByName($oIE, "mainGabblyFrame")
_IELoadWait($oFrame)

$oNickName = _IEGetObjByName($oFrame, "gabblyNicknameTextField")
$oNickChange = _IEGetObjByName($oFrame, "gabblyNicknameButton")
$oMsgField = _IEGetObjByName($oFrame, "gabblyMsgInputField")

_IEFormElementSetValue($oNickName, $sNickname)
_IEAction($oNickChange, "click")
_IELoadWait($oFrame)

_IEFormElementSetValue($oMsgField, $sMessage)
_IEAction($oMsgField, "focus")
ControlSend($hwnd, "", "Internet Explorer_Server1", "{Enter}")
Link to comment
Share on other sites

Thanks big_daddy for the code. It worked but not the way I would like.

In your code, when you set focus to that text box, the chat window was activated.

I want the script to work silently. I am wondering if there is anyway to send an enter key to a certain object silently (instead of activate that window and then send).

Many thanks!

Link to comment
Share on other sites

Hi,

I met another problem with Frame Elements.

I tried to locate objects inside the gabbly chatroom frame of this site: (removed)

I noticed the gabbly chatroom is tagged with IFRAME (i.e. it is a Frame Element as DaleHohm said in another thread).

I had a look at this topic on "Working with Frames":

http://www.autoitscript.com/forum/index.ph...0&hl=IFRAME

I also tried IE Dev Toolbar and MODIv2. Both just returned the URL source of that frame (i.e. src). It means the frame is not what I see on the page, instead it is just the link to another site.

I tried Developer Tool of Firefox. It can locate and provide information of all objects inside that frame element.

In the AutoIt code, if I used:

a. _IEFrameGetCollection ($oIE) ==> It returned 1 frame, but the frame has no name or source.

b. _IETagNameGetCollection ($oIE, "frame") ==> It returned 0 frame.

c. _IETagNameGetCollection ($oIE, "IFrame") ==> It returned 1 frame which contains the correct URL link to the actual page (on a different domain).

I am wondering how I could locate and grab objects from that frame.

I tried to grab the nickname object by the following code:

$oFrame = _IETagNameGetCollection ($oIE, "IFrame", 0)
$oNickName = _IEGetObjByName($oFrame, "gabblyNicknameTextField")

...but it didn't work.

Could anyone please give me some help or directions?

Many thanks!

Edited by svkhtn
Link to comment
Share on other sites

Use

$oFrame = _IEFrameGetCollection ($oIE, 0)

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

Use

$oFrame = _IEFrameGetCollection ($oIE, 0)

Dale

I tried and mentioned in my previous post (i.e. I tried to grab the whole collection or the first one as you mentioned). It didn't work.

@big_daddy: yes, the problem is cross-site scripting. I am wondering if you know any solution to this.

Many thanks!

Link to comment
Share on other sites

The work-around I have suggested to others is to display the contents of the frame in a new browser window instead of trying to manipulate it in a frame.

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

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