Friday, May 6, 2011

Some text parsing examples

If a page contains e.g. user information in a format:

Name: John
Gender: Male
...

an easy way to get the name is:

$name = $ie.text.slice(Regexp.new('Name: .*?$')).sub("Name: ","")

Another way is to:

$firstarray = $ie.html.split("Name: ")
$secondarray = $firstarray[1].split(/<br>/)
$name = $secondarray[0]

No comments:

Post a Comment