How to read table's cell in ruby ?

  • Thread starter Deepak Kumar Shivhare
  • Start date
D

Deepak Kumar Shivhare

Hello,

Can anyone tell me how to read cells of a table on a webpage?
plz tell me methods.

Thanks in Advance
Deepak
 
P

Peter Szinek

Deepak said:
Hello,

Can anyone tell me how to read cells of a table on a webpage?
plz tell me methods.

Check out scRUBYt!:

http://scrubyt.org

Quick example:

Input
=================================================================
<html>
<body>
<table border=1 padding=10>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
<br/>
<table border=1 padding=10>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td>8</td>
</tr>
</table>
<br>
<table border=1 padding=10>
<tr>
<td>9</td>
<td>10</td>
</tr>
<tr>
</tr>
<tr>
<td>11</td>
</tr>
</table>
</body>
</html>
=================================================================

scRUBYt program to extract all the cells:

=================================================================
table_data = Scrubyt::Extractor.define do

fetch "input.html"

cell '1'
end
=================================================================

output:

=================================================================
<root>
<cell>1</cell>
<cell>2</cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell>6</cell>
<cell>7</cell>
<cell>8</cell>
<cell>9</cell>
<cell>10</cell>
<cell>11</cell>
</root>
=================================================================

Cheers,
Peter
__
http://www.rubyrailways.com :: Ruby and Web2.0 blog
http://scrubyt.org :: Ruby web scraping framework
http://rubykitchensink.ca/ :: The indexed archive of all things Ruby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top