Jump to content

StringBetween doesnt work


Lyee
 Share

Recommended Posts

Hi guys,

I have some problems, I have a source code and I need got just 1 random word and StringBetween doesnt work and I actually dont know already I spend to much time and still I dont get it..

<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">Hi</span>

And I have code which doesnt work:

Global $Website = _IECreate('http://')
Global $sHtml = _IEBodyReadHTML($WebSite)
Global $_Word = _StringBetween($sHtml , '<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">', '</span>')
    If IsArray($_Word) Then
        $_Word = $_Word[1]
    EndIf
    Send($_Word)

All of there seems correct

Link to comment
Share on other sites

Arrays are 0 based, use $_Word[0] unless you're expecting multiple matches

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Does this work:

#include <String.au3>

$teststring = '<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">Hi</span>'
MsgBox(0, "Input String", $teststring)
$parsedstring = _StringBetween($teststring , '<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">','</span>')
MsgBox(0, "Parsed String", $parsedstring[0])
If IsArray($parsedstring) Then $parsedstring = $parsedstring[0]
MsgBox(0, "Parsed String To Array", $parsedstring)

?

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Try this:

#include <IE.au3>
#include <String.au3>

$hGUI = GUICreate("IEHotFix", 50, 50)
$hTemp = GUICtrlCreateEdit("", 0, 0, 50, 50)
$Website = _IECreate('http://')
$sHtml = GUICtrlRead(GUICtrlSetData($hTemp, _IEBodyReadHTML($WebSite)))
$_Word = _StringBetween($sHtml , '<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">', '</span>')
If IsArray($_Word) Then $_Word = $_Word[0]

 

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

11 minutes ago, rcmaehl said:

Try this:

#include <IE.au3>
#include <String.au3>

$hGUI = GUICreate("IEHotFix", 50, 50)
$hTemp = GUICtrlCreateEdit("", 0, 0, 50, 50)
$Website = _IECreate('http://')
$sHtml = GUICtrlRead(GUICtrlSetData($hTemp, _IEBodyReadHTML($WebSite)))
$_Word = _StringBetween($sHtml , '<span id="nhwMiddlegwt-uid-8" style="text-decoration: underline; color: rgb(153, 204, 0);">', '</span>')
If IsArray($_Word) Then $_Word = $_Word[0]

 

As always - "0". Idk wtf is going on here..

Link to comment
Share on other sites

_IEBodyReadHTML funkiness when being parsed by other functions is my guess

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

For example this website http://www.statnisprava.cz/rstsp/ciselniky.nsf/i/d0055?opendocument&:CZ031

There is a lot of emails in pages. I just want to copy them to notepad.

here is my code:

#include <IE.au3>
#include <String.au3>

Global $NP = Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)


Local $oIE = _IECreate("http://www.statnisprava.cz/rstsp/ciselniky.nsf/i/d0055?opendocument&:CZ031")
Global $sHtml = _IEBodyReadHTML($oIE)
Global $_Text = _StringBetween($sHtml , '<a href="mailto:' & '">', '</a>')

Global $WebCounter = 26

Do
ClickByIndex()
Until $Count = 648

Func ClickByIndex()
    _IELinkClickByIndex($oIE, $WebCounter)
    If IsArray($_Text) Then
        $_Text = $_Text[0]
        WinActivate($hWnd)
        ControlSetText($hWnd, '', "Edit1", $_Text)
    Else
        Exit
    EndIf
    $WebCounter += 1
EndFunc   ;==>ClickByIndex

It's just for one page I know cuz there is not back func.

But I just need to copy that email with Stringbetween func but it does not work.

any idea? :/

Edited by Lyee
Link to comment
Share on other sites

 

I've made a few changes and added some comments (;<=== ) to your script below to help you debug it further

#include <IE.au3>
#include <String.au3>
#include <Array.au3> ;<==== included so that we can examin output from _StringBetween

Global $NP = Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)


Local $oIE = _IECreate("http://www.statnisprava.cz/rstsp/ciselniky.nsf/i/d0055?opendocument&:CZ031")
Global $sHtml = _IEBodyReadHTML($oIE)
;Check what $sHtml actually contains, There is only 1 mailto:
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sHtml = ' & $sHtml & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;Global $_Text = _StringBetween($sHtml , '<a href="mailto:' & '">', '</a>') ;<==== There are no strings starting with '<a href="mailto:">'
Global $_Text = _StringBetween($sHtml , '<a href="mailto:', '</a>') ;<=== use this instead. you will have to do more processing to clean the email address.
_ArrayDisplay($_Text, "Output from _StringBetween") ;<=== Display what _StringBetween found
Global $WebCounter = 26
Do
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WebCounter = ' & $WebCounter & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ClickByIndex()
Until $Count = 648 ;<==== Should $Count be $WebCounter?

Func ClickByIndex()
    _IELinkClickByIndex($oIE, $WebCounter)
    If IsArray($_Text) Then
        $_Text = $_Text[0]
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Text = ' & $_Text & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        WinActivate($hWnd)
        ControlSetText($hWnd, '', "Edit1", $_Text)
    Else
        Exit
    EndIf
    $WebCounter += 1
EndFunc   ;==>ClickByIndex

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

3 hours ago, Bowmore said:

 

I've made a few changes and added some comments (;<=== ) to your script below to help you debug it further

#include <IE.au3>
#include <String.au3>
#include <Array.au3> ;<==== included so that we can examin output from _StringBetween

Global $NP = Run("notepad.exe")
Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)


Local $oIE = _IECreate("http://www.statnisprava.cz/rstsp/ciselniky.nsf/i/d0055?opendocument&:CZ031")
Global $sHtml = _IEBodyReadHTML($oIE)
;Check what $sHtml actually contains, There is only 1 mailto:
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sHtml = ' & $sHtml & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;Global $_Text = _StringBetween($sHtml , '<a href="mailto:' & '">', '</a>') ;<==== There are no strings starting with '<a href="mailto:">'
Global $_Text = _StringBetween($sHtml , '<a href="mailto:', '</a>') ;<=== use this instead. you will have to do more processing to clean the email address.
_ArrayDisplay($_Text, "Output from _StringBetween") ;<=== Display what _StringBetween found
Global $WebCounter = 26
Do
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $WebCounter = ' & $WebCounter & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ClickByIndex()
Until $Count = 648 ;<==== Should $Count be $WebCounter?

Func ClickByIndex()
    _IELinkClickByIndex($oIE, $WebCounter)
    If IsArray($_Text) Then
        $_Text = $_Text[0]
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Text = ' & $_Text & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        WinActivate($hWnd)
        ControlSetText($hWnd, '', "Edit1", $_Text)
    Else
        Exit
    EndIf
    $WebCounter += 1
EndFunc   ;==>ClickByIndex

 

Thank you it helped me a lot.

Now I have a question..

Why is there "ConsoleWrite..."? It looks like it doesnt matter if this line is not there.

 

Link to comment
Share on other sites

You are correct, the ConsoleWrite is not required, I was using it in the Scite editor to display the value of $_stext.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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