Sign in to follow this  
Followers 0
Surviver

[SOLVED] working with data from HTML

9 posts in this topic

#1 ·  Posted (edited)

I have a HTML page, and it contain some javascripts like those ones that are used for surveys...Now, on the middle of the page, I have my portion of code wich I wish to display it (including the picture) on a GUI when the button is pressed. The problem is that I don't know how to fo it...Here is the piece of code that I want to manipulate:

<center><b>Video Details</b><br />
<table border="1">

<tr>
<td colspan="2"><b>Original URL:</b> <a href="http://megavideo.com/?v=UOXLMD16" target="_blank">http://megavideo.com/?v=UOXLMD16</a></td>
</tr>
<tr>
<td><b>Screen cap:</b><br /><img src="http://img10.megavideo.com/da68068c348a73bc6e400936a646e50f.jpg" /></td>
<td valign="top">
<b>Title:</b> the truth aboutlove<br />
<b>Description:</b> the truth aboutlove<br />

<b>Run time:</b> 94:46<br />
<b>Original file name:</b> video.flv<br />
<b>Original file size:</b> 394.42 MB<br /><br />
<form name="frmOri" id="frmOri" method="post" action="origen.php">
<input type="hidden" name="v" id="v" value="UOXLMD16" />
<input type="hidden" name="vtitle" id="vtitle" value="the truth aboutlove" />
<input type="hidden" name="vsize" id="vsize" value="413576975" />
<center>

The GUI looks like:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Video Details", 620, 206, 192, 124)
$Label1 = GUICtrlCreateLabel("Oriiginal URL:", 8, 8, 69, 17)
$Input1 = GUICtrlCreateInput("Input1", 112, 8, 121, 21)
$Label2 = GUICtrlCreateLabel("Title:", 8, 40, 27, 17)
$Input2 = GUICtrlCreateInput("Input2", 112, 40, 121, 21)
$Label3 = GUICtrlCreateLabel("Description:", 8, 72, 60, 17)
$Input3 = GUICtrlCreateInput("Input3", 112, 72, 121, 21)
$Label4 = GUICtrlCreateLabel("Run Time:", 8, 104, 53, 17)
$Input4 = GUICtrlCreateInput("Input4", 112, 104, 121, 21)
$Label5 = GUICtrlCreateLabel("Original File Name:", 8, 136, 92, 17)
$Input5 = GUICtrlCreateInput("Input5", 112, 136, 121, 21)
$Label6 = GUICtrlCreateLabel("Original File Size;", 8, 168, 84, 17)
$Input6 = GUICtrlCreateInput("Input6", 112, 168, 121, 21)
$Pic1 = GUICtrlCreatePic("", 240, 8, 372, 188)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by Surviver

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is one of the easiest to understand ways to do it:

Just pass the source string to the _SetData function to set all controls. Sending a blank string will clear the controls.

(example only fills the first two inputs and the image, the other inputs can be done in the same way as the first two.)

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <string.au3>

Global $sData1 = '<center><b>Video Details</b><br />' & @CRLF & _
'<table border="1">' & @CRLF & _
@CRLF & _
'<tr>' & @CRLF & _
'<td colspan="2"><b>Original URL:</b> <a href="http://megavideo.com/?v=UOXLMD16" target="_blank">http://megavideo.com/?v=UOXLMD16</a></td>' & @CRLF & _
'</tr>' & @CRLF & _
'<tr>' & @CRLF & _
'<td><b>Screen cap:</b><br /><img src="http://img10.megavideo.com/da68068c348a73bc6e400936a646e50f.jpg" /></td>' & @CRLF & _
'<td valign="top">' & @CRLF & _
'<b>Title:</b> the truth aboutlove<br />' & @CRLF & _
'<b>Description:</b> the truth aboutlove<br />' & @CRLF & _
@CRLF & _
'<b>Run time:</b> 94:46<br />' & @CRLF & _
'<b>Original file name:</b> video.flv<br />' & @CRLF & _
'<b>Original file size:</b> 394.42 MB<br /><br />' & @CRLF & _
'<form name="frmOri" id="frmOri" method="post" action="origen.php">' & @CRLF & _
'<input type="hidden" name="v" id="v" value="UOXLMD16" />' & @CRLF & _
'<input type="hidden" name="vtitle" id="vtitle" value="the truth aboutlove" />' & @CRLF & _
'<input type="hidden" name="vsize" id="vsize" value="413576975" />' & @CRLF & _
'<center>'

Global $Form1 = GUICreate("Video Details", 620, 238, 192, 124)
Global $Label1 = GUICtrlCreateLabel("Original URL:", 8, 8, 69, 17)
Global $Input1 = GUICtrlCreateInput("Input1", 112, 8, 121, 21)
Global $Label2 = GUICtrlCreateLabel("Title:", 8, 40, 27, 17)
Global $Input2 = GUICtrlCreateInput("Input2", 112, 40, 121, 21)
Global $Label3 = GUICtrlCreateLabel("Description:", 8, 72, 60, 17)
Global $Input3 = GUICtrlCreateInput("Input3", 112, 72, 121, 21)
Global $Label4 = GUICtrlCreateLabel("Run Time:", 8, 104, 53, 17)
Global $Input4 = GUICtrlCreateInput("Input4", 112, 104, 121, 21)
Global $Label5 = GUICtrlCreateLabel("Original File Name:", 8, 136, 92, 17)
Global $Input5 = GUICtrlCreateInput("Input5", 112, 136, 121, 21)
Global $Label6 = GUICtrlCreateLabel("Original File Size;", 8, 168, 84, 17)
Global $Input6 = GUICtrlCreateInput("Input6", 112, 168, 121, 21)
Global $Button1 = GUICtrlCreateButton("Set data 1",8,200,100,20)
Global $Pic1 = GUICtrlCreatePic("", 240, 8, 372, 188)
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _SetData($sData1)
    EndSwitch
WEnd

Func _SetData($sSource)
    GUISetCursor(15,1,$Form1)
    Local $aTemp

    $aTemp = _StringBetween($sSource,'<b>Original URL:</b> <a href="','"')
    If @error Then
        GUICtrlSetData($Input1,"")
    Else
        GUICtrlSetData($Input1,$aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Title:</b>','<br />')
    If @error Then
        GUICtrlSetData($Input2,"")
    Else
        GUICtrlSetData($Input2,$aTemp[0])
    EndIf
    ;etc...
    ;the most basic way to display the image I could think of:
    $aTemp = _StringBetween($sSource,'<img src="','"')
    If @error Or Not InetGet($aTemp[0],@TempDir & "\img.jpg") Then
        GUICtrlSetImage($Pic1,"")
    Else
        GUICtrlSetImage($Pic1,@TempDir & "\img.jpg")
    EndIf
    FileDelete(@TempDir & "\img.jpg")
    ;a little more complicated, but nicer would be to use the background  parameter and set the image, if and when it is downloaded. Keeping your  UI responsive during the download.
    ;I believe the best way would  be to get the image using WinHTTP (keeping the UI responsive and  without creating a temp file) and displaying that using GDI+, but that's  pretty complicated.
    GUISetCursor()
EndFunc

Edit:

Reading your post again, you probably don't have the source yet. You can get it using something like this:

$sUrl = "Url of the page containing the source"
$sSource = _StringBetween(BinaryToString(InetRead($sUrl)),'<center><b>Video Details</b>','<center>')
Edited by Tvern

Share this post


Link to post
Share on other sites

But there is another problem: What if I use an embedded IE in a main GUI ? How can I get the source? (i'm a very very beginner)

Share this post


Link to post
Share on other sites

_IEBodyReadHTML

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well, thank you, but is working just for the URL and for the picture. Here is how I've done:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <string.au3>
#include<ie.au3>

$Form1 = GUICreate("Video Details", 620, 238, 192, 124)
$Label1 = GUICtrlCreateLabel("Original URL:", 8, 8, 69, 17)
$Input1 = GUICtrlCreateInput("Input1", 112, 8, 121, 21)
$Label2 = GUICtrlCreateLabel("Title:", 8, 40, 27, 17)
$Input2 = GUICtrlCreateInput("Input2", 112, 40, 121, 21)
$Label3 = GUICtrlCreateLabel("Description:", 8, 72, 60, 17)
$Input3 = GUICtrlCreateInput("Input3", 112, 72, 121, 21)
$Label4 = GUICtrlCreateLabel("Run Time:", 8, 104, 53, 17)
$Input4 = GUICtrlCreateInput("Input4", 112, 104, 121, 21)
$Label5 = GUICtrlCreateLabel("Original File Name:", 8, 136, 92, 17)
$Input5 = GUICtrlCreateInput("Input5", 112, 136, 121, 21)
$Label6 = GUICtrlCreateLabel("Original File Size;", 8, 168, 84, 17)
$Input6 = GUICtrlCreateInput("Input6", 112, 168, 121, 21)
$Button1 = GUICtrlCreateButton("Set data 1", 8, 200, 100, 20)
$Pic1 = GUICtrlCreatePic("", 240, 8, 372, 188)
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            $sUrl = _IECreate("http://personalized.x10.mx/blah%20details.html", 0, 1, 1)
;~          $TheSource = _StringBetween(BinaryToString(InetRead($sUrl)), '<center><b>Video Details</b>', '<center>')
            $sData1 = _IEBodyReadHTML($sUrl)
            _SetData($sData1)
    EndSwitch
WEnd

Func _SetData($sSource)
    Local $aTemp

    $aTemp = _StringBetween($sSource, '<b>Original URL:</b> <a href="', '"')
    If @error Then
        GUICtrlSetData($Input1, "")
    Else
        GUICtrlSetData($Input1, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource, '<b>Title:</b> ', '<br />',1)
    If @error Then
        GUICtrlSetData($Input2, "")
    Else
        GUICtrlSetData($Input2, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Description:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input3, "")
    Else
        GUICtrlSetData($Input3, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Run time:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input4, "")
    Else
        GUICtrlSetData($Input4, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Original file name:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input5, "")
    Else
        GUICtrlSetData($Input5, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Original file size:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input6, "")
    Else
        GUICtrlSetData($Input6, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource, '<img src="', '"')
    If @error Or Not InetGet($aTemp[0], @TempDir & "\img.jpg") Then
        GUICtrlSetImage($Pic1, "")
    Else
        GUICtrlSetImage($Pic1, @TempDir & "\img.jpg")
    EndIf
    FileDelete(@TempDir & "\img.jpg")

EndFunc   ;==>_SetData

Now, where is the problem?

Edited by Surviver

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

_IEBodyReadHTML() works with IE objects not with strings.

Like here:

$IE = _IECreate($URL)
$READ = _IEBodyReadHTML($IE)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

_IEBodyReadHTML() works with IE objects not with strings.

Like here:

$IE = _IECreate($URL)
$READ = _IEBodyReadHTML($IE)

The name might be a little confusing, but $sUrl is an IE object. The problem is that Surviver set _StringBetween to be case sensitive and IE likes to change all HTML tags to uppercase, even if the page source has them lowercase.

I'd avoid using the _IE function for this as it will be noticably slower to load and instead take a look at this:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <string.au3>
#include<ie.au3>

$Form1 = GUICreate("Video Details", 620, 238, 192, 124)
$Label1 = GUICtrlCreateLabel("Original URL:", 8, 8, 69, 17)
$Input1 = GUICtrlCreateInput("Input1", 112, 8, 121, 21)
$Label2 = GUICtrlCreateLabel("Title:", 8, 40, 27, 17)
$Input2 = GUICtrlCreateInput("Input2", 112, 40, 121, 21)
$Label3 = GUICtrlCreateLabel("Description:", 8, 72, 60, 17)
$Input3 = GUICtrlCreateInput("Input3", 112, 72, 121, 21)
$Label4 = GUICtrlCreateLabel("Run Time:", 8, 104, 53, 17)
$Input4 = GUICtrlCreateInput("Input4", 112, 104, 121, 21)
$Label5 = GUICtrlCreateLabel("Original File Name:", 8, 136, 92, 17)
$Input5 = GUICtrlCreateInput("Input5", 112, 136, 121, 21)
$Label6 = GUICtrlCreateLabel("Original File Size;", 8, 168, 84, 17)
$Input6 = GUICtrlCreateInput("Input6", 112, 168, 121, 21)
$Button1 = GUICtrlCreateButton("Set data 1", 8, 200, 100, 20)
$Pic1 = GUICtrlCreatePic("", 240, 8, 372, 188)
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
         $sUrl = InputBox("Load details","Please specify the url to load","http://personalized.x10.mx/blah%20details.html")
            _SetData($sUrl)
    EndSwitch
WEnd

Func _SetData($sUrl)
    Local $aTemp
    Local $sSource = BinaryToString(InetRead($sUrl))

    $aTemp = _StringBetween($sSource, '<b>Original URL:</b> <a href="', '"')
    If @error Then
        GUICtrlSetData($Input1, "")
    Else
        GUICtrlSetData($Input1, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource, '<b>Title:</b> ', '<br />',1)
    If @error Then
        GUICtrlSetData($Input2, "")
    Else
        GUICtrlSetData($Input2, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Description:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input3, "")
    Else
        GUICtrlSetData($Input3, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Run time:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input4, "")
    Else
        GUICtrlSetData($Input4, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Original file name:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input5, "")
    Else
        GUICtrlSetData($Input5, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource,'<b>Original file size:</b> ','<br />',1)
    if @error Then
        GUICtrlSetData($Input6, "")
    Else
        GUICtrlSetData($Input6, $aTemp[0])
    EndIf
    $aTemp = _StringBetween($sSource, '<img src="', '"')
    If @error Or Not InetGet($aTemp[0], @TempDir & "\img.jpg") Then
        GUICtrlSetImage($Pic1, "")
    Else
        GUICtrlSetImage($Pic1, @TempDir & "\img.jpg")
    EndIf
    FileDelete(@TempDir & "\img.jpg")

EndFunc   ;==>_SetData

If you want to use _IEBodyReadHTML(), then you have to change your stringbetweens to case-insensitive, or adjust the parameters to use uppercase HTML tags.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

^Right, I didn't saw.

@Surviver be careful at variables types. Take a look here [Variable names section].

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I've set it to be case sensitive because Iìve tried already without being casse sensitive and the result was the same.Anyway thank you. If I'll have problems, I will write back.

Edit: The problem is that I have a main GUI, with an IEObject,this main gui has a button that creates the GUI that is up. So I must find a way for getting the source form the embedded IEObject...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include<GuiEdit.au3>
#include <IE.au3>
#include<String.au3>
#include<File.au3>
$MainGui = GUICreate("MainGUI", 430, 438, 192, 124)

$MovieInfo = GUICtrlCreateButton("Show Movie Info", 10, 390, 405, 40)

GUISetState(@SW_SHOW)
$oIE = _IECreateEmbedded()
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 120, 400, 260)
_IENavigate($oIE, "http://personalized.x10.mx/blah%20details.html")
While 1

    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $MovieInfo
            $Form1 = GUICreate("Video Details", 620, 238, 192, 124)
            $Label1 = GUICtrlCreateLabel("Original URL:", 8, 8, 69, 17)
            $Input1 = GUICtrlCreateInput("Input1", 112, 8, 121, 21)
            $Label2 = GUICtrlCreateLabel("Title:", 8, 40, 27, 17)
            $Input2 = GUICtrlCreateInput("Input2", 112, 40, 121, 21)
            $Label3 = GUICtrlCreateLabel("Description:", 8, 72, 60, 17)
            $Input3 = GUICtrlCreateInput("Input3", 112, 72, 121, 21)
            $Label4 = GUICtrlCreateLabel("Run Time:", 8, 104, 53, 17)
            $Input4 = GUICtrlCreateInput("Input4", 112, 104, 121, 21)
            $Label5 = GUICtrlCreateLabel("Original File Name:", 8, 136, 92, 17)
            $Input5 = GUICtrlCreateInput("Input5", 112, 136, 121, 21)
            $Label6 = GUICtrlCreateLabel("Original File Size;", 8, 168, 84, 17)
            $Input6 = GUICtrlCreateInput("Input6", 112, 168, 121, 21)
            $Button1 = GUICtrlCreateButton("Set data 1", 8, 200, 100, 20)
            $Pic1 = GUICtrlCreatePic("", 240, 8, 372, 188)
            GUISetState(@SW_SHOW)
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                    Case $Button1

                        $sUrl = InputBox("Load details", "Please specify the url to load", "http://personalized.x10.mx/blah%20details.html")
                        Local $aTemp
                        Local $sSource = BinaryToString(InetRead($sUrl))

                        $aTemp = _StringBetween($sSource, '<b>Original URL:</b> <a href="', '"')
                        If @error Then
                            GUICtrlSetData($Input1, "")
                        Else
                            GUICtrlSetData($Input1, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<b>Title:</b> ', '<br />', 1)
                        If @error Then
                            GUICtrlSetData($Input2, "")
                        Else
                            GUICtrlSetData($Input2, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<b>Description:</b> ', '<br />', 1)
                        If @error Then
                            GUICtrlSetData($Input3, "")
                        Else
                            GUICtrlSetData($Input3, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<b>Run time:</b> ', '<br />', 1)
                        If @error Then
                            GUICtrlSetData($Input4, "")
                        Else
                            GUICtrlSetData($Input4, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<b>Original file name:</b> ', '<br />', 1)
                        If @error Then
                            GUICtrlSetData($Input5, "")
                        Else
                            GUICtrlSetData($Input5, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<b>Original file size:</b> ', '<br />', 1)
                        If @error Then
                            GUICtrlSetData($Input6, "")
                        Else
                            GUICtrlSetData($Input6, $aTemp[0])
                        EndIf
                        $aTemp = _StringBetween($sSource, '<img src="', '"')
                        If @error Or Not InetGet($aTemp[0], @TempDir & "\img.jpg") Then
                            GUICtrlSetImage($Pic1, "")
                        Else
                            GUICtrlSetImage($Pic1, @TempDir & "\img.jpg")
                        EndIf
                        FileDelete(@TempDir & "\img.jpg")
                EndSwitch
            WEnd
    EndSelect
WEnd

Edit 2: I finaly solved, by making HTML tags uppercase. Thank you all for the help.

Edited by Surviver

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