Jump to content

string between ???


Maximus1
 Share

Recommended Posts

i`m trying to read some text from a website but it won`t work.

cn you help me out please?

#include <IE.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include "C:\Dokumente und Einstellungen\t.nawrath\Desktop\autoit\install\Include\Array.au3"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

$left = '* html body { margin-top: 0px; }'
$right = '.sans { font-family: verdana,arial,helvetica,sans-serif; font-size: small; }'

$oIE = _IECreateEmbedded ()
$gui = GUICreate("Embedded Internet Explorer", 1024, 850,(@DesktopWidth-1920)/2, (@DesktopHeight-1080)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUICtrlCreateObj($oIE, 10, 40 , 1000 , 700)
$GUI_Button_Back    = GuiCtrlCreateButton   ("Back",     10, 800, 100,  30)
$GUI_Button_Forward = GuiCtrlCreateButton   ("Forward", 120, 800, 100,  30)
$GUI_Button_Home    = GuiCtrlCreateButton   ("Home",    230, 800, 100,  30)
$GUI_Button_Stop    = GuiCtrlCreateButton   ("Stop",    330, 800, 100,  30)
$GUI_Button_ueber   = GuiCtrlCreateButton   ("Übertragen",    430, 800, 100,  30)
GUISetState()

_IENavigate ($oIE, "http://www.amazon.de")
_IELoadWait ($oIE)
BinaryToString($oIE)
$source = _StringBetween($oIE, $left,$right)
_ArrayDisplay($source,"test")                              ;does not show anything
MsgBox(0,"",""& $source[0])                                ;gives an error

==> Subscript used with non-Array variable.:

MsgBox(0,"",""& $source[0])

MsgBox(0,"",""& $source^ ERROR

Why and how to do it the right way?

Link to comment
Share on other sites

Try

_IENavigate ($oIE, "http://www.amazon.de")
_IELoadWait ($oIE)
$sHTML = _IEDocReadHTML ($oIE)
;ConsoleWrite ( "$sHTML : " & $sHTML & @Crlf )
$source = _StringBetween($sHTML, $left,$right)
If Not @error Then
     _ArrayDisplay($source,"test")                          
     MsgBox(0,"",""& $source[0])      
EndIf
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

hi, thanks it worked.

after i added it to my script, it did not work anymore. :-(

can you help me again please?

in the following html code i wan`t to find "Steuerkuriosa seit Menschengedenken. Trostbilder für Steuerzahler aus fünf Jahrtausenden"

<tr>
    <td class="cell">
      <div class="tiny">
    <strong>
      Titel</strong>
  </div>
Steuerkuriosa seit Menschengedenken. Trostbilder für Steuerzahler aus fünf Jahrtausenden<p class="tiny">
  <strong>

the following will always present the error msgbox at Else.

Global $left = ''
Global $right = '<p class="tiny">'
.
.
.
.
.
.
_IELoadWait ($oIE)
$sHTML = _IEDocReadHTML ($oIE)
;ConsoleWrite ( "$sHTML : " & $sHTML & @Crlf )
$source = _StringBetween($sHTML, $left,$right)
If Not @error Then
    _ArrayDisplay($source,"test")                          
    MsgBox(0,"",""& $source[0])
Else
    MsgBox(0,"","fehler nicht gefunden")            
EndIf
Edited by Maximus1
Link to comment
Share on other sites

maximus1,

this works for me

#Include <Array.au3>
#Include <String.au3>

Local $Text = '<tr>     <td class="cell">      <div class="tiny">    <strong>      Titel</strong>  </div>Steuerkuriosa seit Menschengedenken. Trostbilder für Steuerzahler aus fünf Jahrtausenden<p class="tiny">   <strong>'

Global $left = '</div>'
Global $right = '<p class="tiny">'

$source = _StringBetween($Text, $left,$right)
If Not @error Then
    _ArrayDisplay($source,"test")
    MsgBox(0,"",""& $source[0])
Else
    MsgBox(0,"","fehler nicht gefunden")
EndIf

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

You could eliminate the linefeeds before cutting the string like

$sText = StringReplace ( $sText, @LF, "" )  ; eliminates all linefeeds
$sText = StringReplace ( $sText, @CR, "" )  ; eliminates all carriagereturn
$sText = StringReplace ( $sText, @CRLF, "" )  ; eliminates all carriagereturn-linefeeds

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

  • Developers

You could eliminate the linefeeds before cutting the string like

$sText = StringReplace ( $sText, @LF, "" )  ; eliminates all linefeeds
$sText = StringReplace ( $sText, @CR, "" )  ; eliminates all carriagereturn
$sText = StringReplace ( $sText, @CRLF, "" )  ; eliminates all carriagereturn-linefeeds

A-Jay

Don't think you would need the @CRLF replace any more. :x

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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