Jump to content

_StringBetween with text on 2 lines


Floppy
 Share

Recommended Posts

Hi, I'm trying to get 'abc' from the following code (extracted from a web page)

class="item">
<div style="display: none;" class="cms">abc</div>

AutoIT script

$body = _IEBodyReadHTML($ie)
$result = _StringBetween($body, 'class="item"> <div style="display: none;" class="cms">', '</div>')

It doesn't find anything because I don't know how to specify that the text is on two lines. Can someone help me, please?

Link to comment
Share on other sites

Never mind, just try this.

$body = _IEBodyReadHTML($ie)
$body= StringStripWS($String, 8)
$result = _StringBetween($String, 'class="item"><divstyle="display:none;"class="cms">', '</div>')

first you strip any white space, which includes line feeds and such.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Or more conservative in stripping only linefeeds between > and < tags.

$body = _IEBodyReadHTML($ie)
$body= StringRegExpReplace($body, '>[rn]+<', '><')
$result = _StringBetween($String, '<class="item"><div style="display: none;" class="cms">', '</div>')

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

I'm always posting these, but I'd rather (and suggest), the use of any DOM object to parse out data from [xml|XML-like] structures.

$oXML=ObjCreate("Microsoft.XMLDOM")
$sXML= '<root><li class="item"><div style="display: none;" class="cms">abc</div></li></root>'
$oXML.loadxml($sXML)
;ConsoleWrite ( $oXML.xml & @CRLF )
$oElement = $oXML.SelectSingleNode ( "//li[@class='item']/div[@class='cms']" )
ConsoleWrite ( $oElement.text & @CRLF )
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...