Jump to content

Recommended Posts

<?php

set_time_limit(0);

$start = 0;
$cuvant = urlencode("music");
$path = array("/images");

   $url = "http://www.google.com/cse?cx=013269018370076798483%3Awdba3dlnxqm&q=$cuvant&num=100&hl=en&as_qdr=all&start=$start&sa=N ";   
   $go = true;
   
   while( $go ) {
      // req google
      $data = get_url($url,$cuvant,$start);
  @preg_match_all("/<h2 class=(.*?)><a href=\"(.*?)\" class=(.*?)>/", $data, $rezultate);
        
     
      // verificam adca mai sunt rezultate
      if( count($rezultate) == 0 ) {
         $go = false;
         break;
      }
            
      // procesam fiecare rezultat
      foreach( $rezultate as $r ) {
         echo $r['url']."\n";
         executa($r['url']);
      }   
      }

function get_url($url,$h=false) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	if( $h ) {
		curl_setopt($ch, CURLOPT_HEADER, true); 
		curl_setopt($ch, CURLOPT_NOBODY, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_MAXREDIRS, 10); 			
	}
	curl_setopt($ch, CURLOPT_TIMEOUT, 15); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
}

function status($url) {
	$data = get_url($url,true);
	preg_match("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
	if( count($matches) > 0 ) {
		if( $matches[1] == 200 ) return true;
		else return false;
	} else {
		 return false;
	}
}

function scrie($fis,$txt) {
	$f = fopen($fis,'a');
	fwrite($f,$txt);
	fclose($f);
}

function executa($url) {
	global $path;
	foreach( $path as $p ) {
		$site = parse_url($url);
		$done = "http://".$site['host']."/";
		if( status($done.$p) ) {
			scrie("found.txt",$done.$p."\n");
			echo $done.$p."\n\n\n" .$done.$p. " -> found!!\n\n\n";
		} else {
			echo $done.$p."     -     404!!\n";
		}		
	}		
}
?>

 

I have this code but doesn't work how I want.. This code searches on google for all the websites that have directory /images open but doesn't parse the website I can't figure it out why

Can someone help me ?

Link to comment
https://forums.phpfreaks.com/topic/181857-cant-handle-with-this/
Share on other sites

Whats not working exactly ?

 

one thing i can see thing that just don't make logical sense is

 

$data = get_url($url,$cuvant,$start);

Yet

function get_url($url,$h=false) {

 

 

also

echo $r['url']."\n";

can't be right

i'm sure it should be loop thought the $rezultate[2] as $r and then use $r as the URL

if you try the script on your localhost you will see it doesn't parse the websites from google results. he is trying directory /images on http:///images instead of http://site.com/images

and I can't fix it.. so can you please run the script on your local and see whats the problem? I do not have other option. It is a nightmare for me this script

So now its down to you to write the code.. This is the "Help" section after all, if you want someone to do all the work your need to use the freelance section and pay for it.

 

I have given you a few bug fixes for you to apply, let me what problems you get and I'll try to help.

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.