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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts

    parse href attribute?

    Right, so there are a bunch of links in this format:
    <a href="/profiles/########">username</a>

    I'm using greasemonkey, and what I want to do is go through and get all of the /profiles/######## part of the anchor tag. I'm using Regex and I can't seem to get a match.

    This is what I have so far:
    Code:
    function ok() {
    var names = document.getElementsByTagName('a');
    var reg = new RegExp("WHAT GOES HERE?");
    var e = "links:\n";
    
    var i = 0;
    
    while(i<10) {
    e += reg.exec(names[i].href) + "\n";
    i++;
    }
    
    
    alert(e);
    }
    
    ok();
    what is actually desired is I want there to be a way I can select these somehow as well..

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    K so I've figured out my problem.. I needed to use getElementsByClassName.. now that I have the numbers, I still need to figure out a way to get them out of the document. I'd rather not make a giant 200 line alert window, is there another easier way? Also, how do I filter out the null results?


  •  

    Posting Permissions

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