Sign in to follow this  
Followers 0
Floppy

_StringBetween with text on 2 lines

8 posts in this topic

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?

Share this post


Link to post
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.

1 person likes this

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

Monkey's are, like, natures humans.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you

Share this post


Link to post
Share on other sites

Why not this? :

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

_Stringbetween returns array. Maybe you dont convert it into string. Msgbox wont show anything. Search in help file for arraytostring or something like that (forgot..)

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