Jump to content
BrianTheLibrarian

trouble reading div tags

Recommended Posts

BrianTheLibrarian

Hello I am trying to read a local html file using the following code:

$tags = _IETagNameGetCollection ($oIE, "div")

For $tag in $tags
    $class_value = $tag.GetAttribute("class")

If $class_value = "info" Then
        $info = $tag.innertext
    EndIf

    If $class_value = "name" Then
        $author = $tag.innertext
    EndIf

    If $class_value = "license" Then
        $license = $tag.innertext
    EndIf

Next

FileWriteLine($file, "Data: "&$info & @TAB & $author & @TAB & $license & @TAB  )

 but it always writes a blank line for the filewriteline.  Here is a sample html file that I wrote that still returns nothing.

<HTML>
<body>
    <div class="info"> Basic Information </div>
    <div class="name"> Username </div>
    <div class="license"> Selected License </div>
</body>
</html>

Any ideas what I am doing wrong?

Share this post


Link to post
Share on other sites
Danyfirex

Hello. Try this:

 

#include <IE.au3>

Local $oIE = _IECreate()
Local $sHTML=FileRead("test.html") ;your html file path here
_IEDocWriteHTML($oIE, $sHTML)
_IEAction($oIE, "refresh")

Local $oInfo=_IEGetObjByClass($oIE,"info")
Local $oName=_IEGetObjByClass($oIE,"name")
Local $oLicense=_IEGetObjByClass($oIE,"license")

ConsoleWrite("Info: " & _IEPropertyGet($oInfo,"innertext") & @CRLF)
ConsoleWrite("Name: " & _IEPropertyGet($oName,"innertext") & @CRLF)
ConsoleWrite("License=: " & _IEPropertyGet($oLicense,"innertext") & @CRLF)


Func _IEGetObjByClass(ByRef $o_object, $s_Class, $i_index = 0)
    If Not IsObj($o_object) Then
        __IEConsoleWriteError("Error", "_IEGetObjByClass", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    If Not __IEIsObjType($o_object, "browserdom") Then
        __IEConsoleWriteError("Error", "_IEGetObjByClass", "$_IEStatus_InvalidObjectType")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    Local $i_found = 0
    ;
    $o_tags = _IETagNameAllGetCollection($o_object)
    For $o_tag In $o_tags
        If String($o_tag.className) = $s_Class Then
            If ($i_found = $i_index) Then
                SetError($_IEStatus_Success)
                Return $o_tag
            Else
                $i_found += 1
            EndIf
        EndIf
    Next
    ;
    __IEConsoleWriteError("Warning", "_IEGetObjByClass", "$_IEStatus_NoMatch", $s_Class)
    SetError($_IEStatus_NoMatch, 2)
    Return 0
EndFunc   ;==>_IEGetObjByClass

Saludos

  • Like 1

Share this post


Link to post
Share on other sites
BrianTheLibrarian

Thanks Danyfirex! That did the job perfectly!

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

×