Jump to content

How can i print the contents of html select tag?


Recommended Posts

Hello everyone, I would like to know how can i print the contents of html select tag.

this is the code:

#include <IE.au3>
#include <Array.au3>
#requireadmin   

$start="Tampere (TMP)"

$oIE = _IECreate ("http://www.ryanair.com/php/sbforms/form.php?")
$SBform = _IEFormGetCollection ($oIE,0)

;Departing from
$o = _IEFormElementGetObjByName ($SBform,"sector1_o")
_IEFormElementOptionselect ($o, $start, 1, "byText")

;Going to
$d = _IEFormElementGetObjByName ($SBform,"sector1_d")
$e=0
For $s In $d
    MsgBox(0, $e,$s)
    $e=$e+1
Next
Exit

I would like to print out the following strings:

Bremen (BRE)

Dublin (DUB)

Frankfurt-Hahn (HHN)

London-Stansted (STN)

Milan (Bergamo) (BGY)

Riga (RIX)

I hope someone can help me.

Thank you.

Link to comment
Share on other sites

#NoTrayIcon
#include <IE.au3>
#include <Array.au3>
#RequireAdmin

$start = "Tampere (TMP)"
$sFile = @ScriptDir & '\TMP(GoingTo).txt'

$oIE = _IECreate("http://www.ryanair.com/php/sbforms/form.php?")
$SBform = _IEFormGetCollection($oIE, 0)

;Departing from
$o = _IEFormElementGetObjByName($SBform, "sector1_o")
_IEFormElementOptionselect($o, $start, 1, "byText")

;Going to
$d = _IEFormElementGetObjByName($SBform, "sector1_d")
$sStr = ''

For $s In $d
    $sStr &= _IEPropertyGet($s, 'innerhtml') & @CRLF
Next

$sStr = StringTrimLeft($sStr, StringInStr($sStr, @CRLF)+1)
FileWrite($sFile, $sStr)
RunWait(@ComSpec & '/c print "' & $sFile & '"', '', @SW_HIDE)
FileDelete($sFile)

Link to comment
Share on other sites

Nothing wrong with the above, but also note that

select elements (like "sector1_o" and "sector1_d") have an options collection. Each option item in the options collection has a value and a text property. In addition the select element has a length property that tells you how many items are in the options collection (actually, the options collection also has this length property and gives you the same value).

$options = $o.options
For $option in $options
    ConsoleWrite($option.value & "|" & $option.text & @CRLF)
Next

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

Nothing wrong with the above, but also note that

select elements (like "sector1_o" and "sector1_d") have an options collection. Each option item in the options collection has a value and a text property. In addition the select element has a length property that tells you how many items are in the options collection (actually, the options collection also has this length property and gives you the same value).

$options = $o.options
For $option in $options
    ConsoleWrite($option.value & "|" & $option.text & @CRLF)
Next

Dale

Thank you very much, so it is perfect!

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