J
Jim Burgess
Using ruby, I am trying to read in lines from a two column html table
and store each line in a two element array. This two element array is in
turn stored in one large array.
The table rows look like this:
<tr class="odd">
<td>Row 1 - Column 1</td>
<td>Row 1 - Column 2</td>
</tr>
...
And, when I'm done, I hoping for this:
[["row1 - col1", "row1, col2"], ["row2 - col1", "row2, col2"], ...]
Can anyone give me any pointers on the correct way to do this.
The code I have come up with so far is this:
f = File.open("file_containing_table.txt", "r")
lines = f.readlines
array_to_hold_rows= []
index = 0
loop do
if lines[index] == nil
break
elsif lines[index].match "<td"
array_to_hold_rows << ["#{lines[index]}", "#{lines[index+1]}"]
index +=2
else
index +=1
end
end
This works and does what I want, but I would like to know if this is the
best / most effective way to go about what I am trying to achieve.
Would be grateful for any help.
and store each line in a two element array. This two element array is in
turn stored in one large array.
The table rows look like this:
<tr class="odd">
<td>Row 1 - Column 1</td>
<td>Row 1 - Column 2</td>
</tr>
...
And, when I'm done, I hoping for this:
[["row1 - col1", "row1, col2"], ["row2 - col1", "row2, col2"], ...]
Can anyone give me any pointers on the correct way to do this.
The code I have come up with so far is this:
f = File.open("file_containing_table.txt", "r")
lines = f.readlines
array_to_hold_rows= []
index = 0
loop do
if lines[index] == nil
break
elsif lines[index].match "<td"
array_to_hold_rows << ["#{lines[index]}", "#{lines[index+1]}"]
index +=2
else
index +=1
end
end
This works and does what I want, but I would like to know if this is the
best / most effective way to go about what I am trying to achieve.
Would be grateful for any help.