Re: Parsing Challenge

new topic     » goto parent     » topic index » view thread      » older message » newer message

Here's quick code w/little error checking, but it works fine on your example
HTML.

include sequence.e
include search.e
include file.e

function get_attr(sequence data, sequence attr, integer start)
    integer stop, max_stop

    max_stop = find_from('>', data, start)
    start = match_from(attr & "=", data, start)
    if start = 0 or start > max_stop then
        return ""
    end if

    stop = find_any_from(" >", data, start)

    return trim(data[start+length(attr)+1..stop-1], "\"")
end function

sequence data, matches
data = read_file("ex.html")

matches = match_all("<div", data, 1)

for i = 1 to length(matches) do
    puts(1, "   Id: " & get_attr(data, "id", matches[i]) & "\n")
    puts(1, "Class: " & get_attr(data, "class", matches[i]) & "\n\n")
end for


It requires the new standard library, but you can grab search.e, sequence.e and
file.e from

http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk/include/

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu