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.

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.