Jump to content

Grabbing Links from Web Page


refined

Recommended Posts

Alright, so basically, I need a function that takes a cURL output from a page and grabs links from inside of the page. The links are all from rapidshare.com, and are generally in this typical format:

 

http://rapidshare.com/files/3459349/etcetcetc.r00

http://rapidshare.com/files/81027576/blahblahblah234.rar

http://www.rapidshare.com/files/81027576/etcetcetc.rar

http://www.rapidshare.com/files/81027576/etdasflkjas.r00

 

These are essentially how the links work. I know how to code everything except for the regex that grabs the link for the page.

 

I've tried several things, including the classic:

function returnSubstrings($text, $openingMarker, $closingMarker) {
$openingMarkerLength = strlen($openingMarker);
$closingMarkerLength = strlen($closingMarker);
$result = array();
$position = 0;
while (($position = strpos($text, $openingMarker, $position)) !== false) {
	$position += $openingMarkerLength;
	if (($closingMarkerPosition = strpos($text, $closingMarker, $position)) !== false) {
		$result[] = substr($text, $position, $closingMarkerPosition - $position);
		$position = $closingMarkerPosition + $closingMarkerLength;
	}
}
return $result;
}
$cURLoutput = str_replace("www.rapidshare.com", "rapidshare.com", $cURLoutput);
$linkarray= returnSubstrings($cURLoutput, "http://rapidshare.com", ".rar");
$linkarray2= returnSubstrings($cURLoutput, "http://rapidshare.com", ".[0-9]");

 

Obviously, I left the cURL stuff out..

 

This is clearly not the most effective way to do this.. what is the best method?

 

Yeah, it's very ugly

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.