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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Complete newbie - help with simple code

    Well, relatively simple.

    I've got a bunch of links in the format as such:

    http://community.giffgaff.com/t5/use.../user-id/24880

    On each page, the page title has the username in it, as does the page itself. I need to make some sort of program (no idea what language it would use) to visit each link and grab the username from it, and accumulate all the usernames in the fashion user1,user2,user3 etc.

    Any idea how to work that? Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    You cannot do that with Javascript. You will need server-side coding. But I have the idea that you would not be able to write such code.

    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    You cannot do that with Javascript. You will need server-side coding. But I have the idea that you would not be able to write such code.

    It is your responsibility to die() if necessary….. - PHP Manual
    Ah OK. So you think I'll have to trawl through each of 600 links manually and type out each username?

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    there are probably much more efficient ways to do this, but as long as you have the user IDs you can put them into the ids array here:

    Code:
    <body>
    <div id="results"></div>
    <script type="text/javascript">
    function showUser(o){
    document.getElementById("results").innerHTML+=o.query.results.body.div.center.div[0].div.div[3].ul.li[2].span.content.split(" ")[1]+"<br>";
    }
    
    var ids=[24880,25580,27380]
    for (var i = 0; i < ids.length; i++) {
    getUser(ids[i])
    }
    
    function getUser(num){
    if (document.getElementById("giffgaff")){
    document.body.removeChild(document.getElementById("giffgaff"));
    }
    var myurl=encodeURIComponent("http://community.giffgaff.com/t5/user/viewprofilepage/user-id/"+num)
    scr=document.createElement("script");
    scr.type="text/javascript";
    scr.id="giffgaff"
    scr.src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22'+myurl+'%2F%22&format=json&callback=showUser';
    document.body.appendChild(scr);
    }
    </script>
    </body>

  • Users who have thanked xelawho for this post:

    wman2 (10-10-2012)

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by xelawho View Post
    there are probably much more efficient ways to do this, but as long as you have the user IDs you can put them into the ids array here:

    Code:
    <body>
    <div id="results"></div>
    <script type="text/javascript">
    function showUser(o){
    document.getElementById("results").innerHTML+=o.query.results.body.div.center.div[0].div.div[3].ul.li[2].span.content.split(" ")[1]+"<br>";
    }
    
    var ids=[24880,25580,27380]
    for (var i = 0; i < ids.length; i++) {
    getUser(ids[i])
    }
    
    function getUser(num){
    if (document.getElementById("giffgaff")){
    document.body.removeChild(document.getElementById("giffgaff"));
    }
    var myurl=encodeURIComponent("http://community.giffgaff.com/t5/user/viewprofilepage/user-id/"+num)
    scr=document.createElement("script");
    scr.type="text/javascript";
    scr.id="giffgaff"
    scr.src='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22'+myurl+'%2F%22&format=json&callback=showUser';
    document.body.appendChild(scr);
    }
    </script>
    </body>
    Xelawho, thank you so so so much! You, sir, are a gentleman and a scholar.

    I used the Microsoft Word find and replace to get the user IDs by themselves then put them into your script, it worked wonders! Thank you very much my friend

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    you're welcome. please do not use it for evil

  • #7
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    you're welcome. please do not use it for evil
    I won't don't worry It's just to inform a load of people by PM in a scheme I run about a change but I didn't have their usernames, only their links and it would have taken hours and hours to do it manually.

    Thanks again!

  • #8
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    ah, I get it. If you want to format the output differently, just change the innerHTML line - if you do it like this it will put a comma and a space after each username:
    Code:
    document.getElementById("results").innerHTML+=o.query.results.body.div.center.div[0].div.div[3].ul.li[2].span.content.split(" ")[1]+", ";

  • #9
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    ah, I get it. If you want to format the output differently, just change the innerHTML line - if you do it like this it will put a comma and a space after each username:
    Code:
    document.getElementById("results").innerHTML+=o.query.results.body.div.center.div[0].div.div[3].ul.li[2].span.content.split(" ")[1]+", ";
    Nice thanks, I've got it how I want it using Word for now but I'll change it for next time


  •  

    Posting Permissions

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