Jump to content

PHP youtube Username Grabber


Lukeidiot

Recommended Posts

I am trying to make an application that grabs the youtube usernames from a given link.

 

Here is an example:

 

I would like to pull the usernames from this url: http://www.youtube.com/browse?s=bzb

 

and display them like such:

Joe1, hello3, test3, hellotest44

 

Is this easy to do? If so could anyone care to assist me with this? :)

 

Thanks in advance.

 

EDIT: Here is an example of kinda what I'd like, but just grabbing different data

http://answers.google.com/answers/threadview/id/36615.html

Link to comment
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

 

Output

Array
(
    [0] => ifbnews
    [1] => sigves
    [2] => lunamaria0708
    [3] => PrismWeapon
    [4] => sugoidrama070109
    [5] => ebonite45
    [6] => AluminumFoils
    [7] => VenetianPrincess
    [8] => NGRNinfa
    [9] => cheezburger
    [10] => MootPoon817
    [11] => SouljaBoy
    [12] => NationalGeographic
    [13] => jobros1love1dream2
    [14] => cplfreeman
    [15] => 10LMessi7CRonaldo
    [16] => betamaxdc
    [17] => failblog
    [18] => DjGhostM
    [19] => jameslikecoulter
    [20] => XxNewXDisneyxX
    [21] => MondoMedia
    [22] => NokiaConversations
)

Link to comment
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

 

Output

Array
(
    [0] => ifbnews
    [1] => sigves
    [2] => lunamaria0708
    [3] => PrismWeapon
    [4] => sugoidrama070109
    [5] => ebonite45
    [6] => AluminumFoils
    [7] => VenetianPrincess
    [8] => NGRNinfa
    [9] => cheezburger
    [10] => MootPoon817
    [11] => SouljaBoy
    [12] => NationalGeographic
    [13] => jobros1love1dream2
    [14] => cplfreeman
    [15] => 10LMessi7CRonaldo
    [16] => betamaxdc
    [17] => failblog
    [18] => DjGhostM
    [19] => jameslikecoulter
    [20] => XxNewXDisneyxX
    [21] => MondoMedia
    [22] => NokiaConversations
)

 

Is this quicker than CURL or the same speed/resources??

Link to comment
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

Link to comment
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

 

 

 

 

This is more flexible:

 

foreach ($matches[1] as $value) {
echo   $value; // add anything you want in front of or after 
}

Link to comment
Share on other sites

<?php
$page = "http://www.youtube.com/browse?s=bzb";
$page_contents = file_get_contents($page);

$names = preg_match_all('/<span class="video-username"><a id="video-from-username-.*" class="hLink"  href="\/user\/(.*)">.*<\/a><\/span>/', $page_contents, $matches);
print_r($matches[1]);

?>

Thank you so much, this is exactly what I was looking for!

 

How would I list them without the array information? For example, make it say this:

user1, user2, user3

 

 

 

 

This is more flexible:

 

foreach ($matches[1] as $value) {
echo   $value; // add anything you want in front of or after 
}

 

Sure if you want your result to be.

 

, name, name, name, name, 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.