Sign in to follow this  
Followers 0
Piyush

how to use xmldomwrapper udf with html files...

5 posts in this topic

#1 ·  Posted (edited)

I want to get cetain value of a text node with the help of xmldomwrapper....

I have posted the source of the page and also an screenshot.In the screen shot u would see word..'Sangrur' in a table below the cell "STATION NAME".I want to get this text with xml domwrapper udf . Please help with this problem.

i had tried but was not able to get it.So i just wanted an xample so that i could proceed further

post-50185-1263290841487_thumb.jpg

Uploader was not able to upload this page source so here it is..:

<HTML>

<HEAD>

</HEAD>

<BR>

<BODY><table border="0" cellPadding="0" cellSpacing="0" width="95%"><tr> <td align="center"> <FONT SIZE = "1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Indian Railways Online Website: <b><a TITLE = "Passenger Reservation System - CONCERT" href="http://www.indianrail.gov.in/index.html" target="_blank">http://www.indianrail.gov.in</b></a> designed and hosted by CRIS.</FONT> </td></tr></table>

<TABLE BORDER ALIGN=center >

<TR>

</TR>

</TABLE>

<H1>Station Names with Station Codes </H1>

<table border="0" width="1005" >

<tr>

<td width="526">

<TABLE BORDER = "1" ALIGN=center font size:1>

<CAPTION> You Queried For </CAPTION>

<TR>

<TH ALIGN = left>Input String</TH>

<TH ALIGN = left>SANGRUR</TH>

</TR>

<TR>

<TH ALIGN = left>Search On</TH>

<TH ALIGN = left>Start String</TH>

</TR>

<TR>

<TH ALIGN = left>Sort Type</TH>

<TH ALIGN = left>Station Name</TH>

</TR>

</TABLE><BR><BR>

<TABLE BORDER = "1" ALIGN=center font size:1>

<TR>

<TH>STATION NAME</TH>

<TH>STATION CODE</TH>

</TR>

<TR>

<TD> <font size="1">SANGRUR </font></TD>

<TD> <font size="1">SAG </font></TD>

</TR>

</TABLE>

</td>

<td width="469" valign="top" align="left" ><div id="narrow_ads_bottom"></div></td>

</tr>

</table>

</BODY>

</HTML>

Edited by Piyush

[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Share this post


Link to post
Share on other sites



Why not using Regex ?


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Why not using Regex ?

i don't know how to use regex.Sorry.i had tried it learning from help file.but i was unable.i will try again.


[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Share this post


Link to post
Share on other sites

i just wanted the xpath to the html element.


[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

i just wanted the xpath to the html element.

You can't use the xmldomwrapper for html-documents.

But you can use:

- the FF.au3 with _FFXPath

- this UDF:

http://thorsten-willert.de/Themen/AutoIt/_HTML.au3

example (your html-source is the text.html in this case):

#include <_HTML.au3>

$HTML = FileRead("c:\\test.html")
MsgBox(0,"",_HTML_GetText($HTML, "td", "", "", 1) )

- or this function:

#Region Includes
#include <IE.au3>
#EndRegion Includes

Main()
Func Main()

    Global $oIE = _IECreate("c:\test.html")

    MsgBox(0, "", _IE_XPath("//table[3]//tr/td[1]/table[2]//tr[2]/td[1]") )

EndFunc   ;==>Main

; #FUNCTION# ===================================================================
; Name ..........: _IE_XPath
; Description ...:
; AutoIt Version : V3.3.0.0
; Syntax ........: _IE_XPath($sXPath[, $sAttribute = "innerText"[, $sIE = "$oIE"]])
; Parameter(s): .: $sXPath      -
;                                 supported @attributes: name | id
;                                 supported functions: position()
;                  $sAttribute  - Optional: (Default = "innerText") :
;                  $sIE         - Optional: (Default = "$oIE") :
; Return Value ..: Success      - string or object
;                  Failure      - empty string
;                  @ERROR       - 1 : No IE-Object
;                                 2 : Attribute not supported
;                                 3 : Error executing statement
; Author(s) .....: Thorsten Willert
; Date ..........: Wed Jan 06 14:17:56 CET 2010
; Version .......: 0.11
; ==============================================================================
Func _IE_XPath($sXPath, $sAttribute = "innerText", $sIE = "$oIE")

    If Not Execute( "IsObj(" & $sIE & ")" ) Then Return SetError(1,0,"")

    Local $a = StringSplit($sXPath, "/")
    Local $aTMP, $pos, $ind, $seg
    Local $sElement = $sIE & ".document", $sSel = "getElementsByTagName"

    For $i = 1 To $a[0]
        $ind = 0
        $seg = StringRegExpReplace($a[$i], '(.*?)\[.*?\]', '$1')
        If StringInStr($a[$i], "[") Then
            $ind = StringRegExpReplace($a[$i], '.*?\[\s*(\d+)\s*\]', '$1') - 1
        EndIf
        If StringInStr($a[$i], "@") Then
            $pos = StringRegExpReplace($a[$i], '.*?\[.*?position\s*\(\)\s*=\s*(\d+).*?\]', '$1') -1
            If $pos = -1 Then $pos = 0
            $aTMP =  StringRegExp($a[$i], '.*?@(\w+)\s*=\s*(''|")(\w+)\2', 3)
            Switch $aTMP[0]
                Case "id"
                    $sSel = "getElementById"
                    $sElement &= StringFormat(".%s('%s')", $sSel, $aTMP[2])
                Case "name"
                    $sSel = "getElementsByName"
                    $sElement &= StringFormat(".%s('%s').item(%s)", $sSel, $aTMP[2], $pos)
                Case Else
                    Return SetError(2,0,"")
            EndSwitch
        Else
            If $seg Then $sElement &= StringFormat(".%s('%s').item(%s)", $sSel, $seg, $ind)
        EndIf

    Next

    If $sAttribute Then $sElement &= "." & $sAttribute

    ConsoleWrite("_IE_XPath: " & $sElement & @CRLF)

    Local $r = Execute($sElement)
    If @error Then Return SetError(3,0,"")

    Return $r
EndFunc   ;==>_IE_XPath
Edited by Stilgar

Share this post


Link to post
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
Sign in to follow this  
Followers 0