Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Extracting data from table columns

    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...icksearch=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

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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):

    Code:
    var emails=[]
    function getEmails() {
    tab=document.getElementById("thetable")
      for (var i = 1; i < tab.rows.length; i++) {
      emails.push(tab.rows[i].cells[4].innerHTML)
    		}
      }

  • Users who have thanked xelawho for this post:

    kevvo (05-20-2012)

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    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
    Everything is simpler with jQuery!

  • Users who have thanked Peeyush for this post:

    kevvo (05-20-2012)

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    oh, sorry - I missed that one. Peeyush is right - if that isn't your page, you can't get at the info using javascript

  • #5
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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
    Last edited by kevvo; 05-20-2012 at 04:15 PM. Reason: typo

  • #6
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Also, how can i getelementbyid when the table has no ID? Is there a way to "add in" an ID to the table?

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    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:
    Code:
    tab=document.body.childNodes[3].childNodes[7]

  • Users who have thanked xelawho for this post:

    kevvo (05-20-2012)

  • #8
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #9
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    @xelawho, cant we add id using js if its his page
    i.e
    Code:
     
    var a = document.getElementsByTagName("table").[some number]
    
    a.id='idYouWantToAdd'
    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
    Last edited by Peeyush; 05-20-2012 at 05:28 PM.
    Everything is simpler with jQuery!

  • #10
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    @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.

  • #11
    New to the CF scene
    Join Date
    May 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Here is what I have come up with.

    Code:
    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?

    kev.

  • #12
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    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.
    Last edited by Peeyush; 05-20-2012 at 06:46 PM. Reason: punct.uatio,n
    Everything is simpler with jQuery!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •