Jump to content

Fetch a page, then grab part of certain URLs


strago

Recommended Posts

How do you have a script, after getting the page, search for and as the result, post *part* of every link that ends like...

 

&v=ANYTHING">Link text</a>

 

and as the result, posting just

 

ANYTHING">Link text<BR>

 

I'm messing with...

 

<?php

$page = $_GET['page'];
$user = $_GET['user'];

$doc = new DOMDocument;
$doc->load('http://m.youtube.com/profile?gl=US&client=mv-google&hl=en&user=$user&view=videos&p=$page');

$items = $doc->getElementsByTagName('a');

foreach($items as $value) {
echo $value->nodeValue . "\n";
$attrs = $value->attributes;
echo $attrs->getNamedItem('href')->nodeValue . "\n";
};

?>

 

but it get's way too much stuff. Get's data from every link on the page, and posts it as

 

Page Text

/watch?gl=US&client=mv-google&hl=en&v=XXXXX

 

And I can't get

 

$page = $_GET['page'];

$user = $_GET['user'];

 

to get the data from the URL.

Link to comment
Share on other sites

<?php

$page = $_GET['page'];
$user = $_GET['user'];

$request_url ="http://m.youtube.com/profile?gl=US&client=mv-google&hl=en&user=$user&view=videos&p=$page";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

//Part of URL to get. videoID">title
$regex='|v=(.*?)</a>|';

preg_match_all($regex,$result,$parts);
$links=$parts[1];
foreach($links as $link){
	echo $link."<br>";
}
curl_close($ch);
?>

 

does it.

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.