View Full Version : Extracting data from table columns

05-20-2012, 03:18 PM
Hi there,

I am trying to extract all of the values from the 5th column (Assignee) in this HTML table http://bugzilla.maptools.org/buglist.cgi?quicksearch=test and don't know how to proceed.

Is there a clever way of getting the entire col class: <col class="bz_op_sys_column"> before putting into an array.

thanks, kev

05-20-2012, 03:40 PM
from what I understand of html tables (and that's not much because I don't really like them), there is no column as such - there are only rows which have cells and the cells line up to appear like columns.

But you can count which cell number you are interested in and search for that in each row, something like this (provided your table has an id):

var emails=[]
function getEmails() {
for (var i = 1; i < tab.rows.length; i++) {

05-20-2012, 03:50 PM
i dont think you can get data by javascript which resides in another server. I have tried to do it once. Anyway i didnt try this method so you can try using getElementById method. I.e. var webdoc = //link of the html page
webdoc.getElementById('id') ;

that way. Bt i do think you cant get it if its on other server

05-20-2012, 03:58 PM
oh, sorry - I missed that one. Peeyush is right - if that isn't your page, you can't get at the info using javascript

05-20-2012, 04:14 PM
Thanks for the replies.

I should have mentioned that I am creating a Greasemonkey script that will handle the extraction using javascript. Does that change anything?

thanks again guys

05-20-2012, 04:38 PM
Also, how can i getelementbyid when the table has no ID? Is there a way to "add in" an ID to the table?

05-20-2012, 05:09 PM
no, you can't insert IDs, and to be honest this thing is looking less likely as it goes on.

But in general if an element has no other identifying feature you can find it according to its location in the DOM, although here you have to be careful because to me it seems that IE counts nodes differently to other browsers. Here's what it would be in Firefox, anyway:


05-20-2012, 05:15 PM
I appreciate your honesty. Thankfully I don't need to worry about IE as i'll only be using this myself. All i need to be able to do is collect all the information from the assignee column into an array from the table i linked above, but because the table has no ID, im stuck big time. thanks again

05-20-2012, 05:23 PM
@xelawho, cant we add id using js if its his page

var a = document.getElementsByTagName("table").[some number]


i have used this before i think we can add id.

Btw @kevvo thanks for thanking me. Its 1st time some one has thanked my post :)

05-20-2012, 05:38 PM
@Peeyush - i always give credit where credit is due. :)

Maybe i am just bad at explaining what i am trying to achieve here. For work, I need to build an array of all the data stored in the Assignee column (column number 4) on this page http://bugzilla.maptools.org/buglist...icksearch=test

I can't modify the page itself, that's why i'm creating a greasemonkey script using javascript to build the array for me once the page is loaded. Sort of like injecting the js into the page once it finishes loading it.

05-20-2012, 05:49 PM
Here is what I have come up with.

for(var i=0;i<document.getElementsByTagName('*').length;i++){
if(document.getElementsByTagName('*')[i].className == 'bz_assigned_to_column'){
document.getElementsByTagName('*')[i].style.backgroundColor = 'red';

If you run this code after the page loads you will see that I am able to get the first cell in the column to change color.
How do i do this for the entire column?


05-20-2012, 06:10 PM
hey. Sorry, I had no idea of what you meant by greasemonkey scripts. Now i hav read a little about them on wikipedia. If you are able to change color of 1 cell, i am sure that it can be done for whole column using loops and DOM. Currently i am browsing on mobile so i wont be able to help much.