google-image-grabber icon indicating copy to clipboard operation
google-image-grabber copied to clipboard

Stopped Grabbing Results

Open barbar-binks opened this issue 3 years ago • 17 comments
trafficstars

First of all, thanks for this amazing tool.

About a week ago, we stopped grabbing images from Google, it seems that something changed in the query that has to be sent, have you experienced anything?

barbar-binks avatar Sep 26 '22 14:09 barbar-binks

It's still working for me.

ericbae avatar Sep 27 '22 11:09 ericbae

Update it to latest and try. It's working now

numairawan avatar Oct 02 '22 04:10 numairawan

Update it to latest and try. It's working now

I will do that, thank you very much.

barbar-binks avatar Oct 05 '22 14:10 barbar-binks

Update it to latest and try. It's working now

Updated and the image array is still showing up empty, is there any way of checking the response from Google? maybe there is something i need to change on my side.

barbar-binks avatar Oct 05 '22 15:10 barbar-binks

i checked again and it's working fine for me. Can you show me your code?

numairawan avatar Oct 06 '22 00:10 numairawan

i checked again and it's working fine for me. Can you show me your code?

yes, a simple search as the example shows as empty:

public function handle() { $keyword = $this->argument("keyword"); $images = GoogleImageGrabber::grab($keyword); print_r($images); return 0; }

barbar-binks avatar Oct 06 '22 16:10 barbar-binks

i checked again and it's working fine for me. Can you show me your code?

yes, a simple search as the example shows as empty:

I am using Laravel 9

barbar-binks avatar Oct 06 '22 16:10 barbar-binks

Your code is working fine for me i think you are not passing the keywords correctly. Try below code code.

public function handle()
{
    $keyword = $this->argument("keyword");
    
    if (!empty($keyword)) {
        return \Buchin\GoogleImageGrabber\GoogleImageGrabber::grab($keyword);   
    } 
    
    return false;
}

numairawan avatar Oct 06 '22 16:10 numairawan

Your code is working fine for me i think you are not passing the keywords correctly. Try below code code.

public function handle()
{
    $keyword = $this->argument("keyword");
    
    if (!empty($keyword)) {
        return \Buchin\GoogleImageGrabber\GoogleImageGrabber::grab($keyword);   
    } 
    
    return false;
}

thank you, i changed it up a bit because this test is a laravel command. I printed the result using this code and using the argument "apple":

` public function handle() { $keyword = $this->argument("keyword"); if (!empty($keyword)) { print_r("your keyword was " . $keyword . "\n"); print_r(\Buchin\GoogleImageGrabber\GoogleImageGrabber::grab($keyword)); return true; } print_r("your keyword was: " . $keyword . "\n"); return false; }

`

got this response:

your keyword was apple Array ( )

barbar-binks avatar Oct 06 '22 16:10 barbar-binks

Your code is working fine for me i think you are not passing the keywords correctly. Try below code code.

public function handle()
{
    $keyword = $this->argument("keyword");
    
    if (!empty($keyword)) {
        return \Buchin\GoogleImageGrabber\GoogleImageGrabber::grab($keyword);   
    } 
    
    return false;
}

thank you, i changed it up a bit because this test is a laravel command. I printed the result using this code and using the argument "apple":

` public function handle() { $keyword = $this->argument("keyword"); if (!empty($keyword)) { print_r("your keyword was " . $keyword . "\n"); print_r(\Buchin\GoogleImageGrabber\GoogleImageGrabber::grab($keyword)); return true; } print_r("your keyword was: " . $keyword . "\n"); return false; }

`

got this response:

your keyword was apple Array ( )

sorry, i'm not github saavy, i dont know how to style code properly

barbar-binks avatar Oct 06 '22 16:10 barbar-binks

Go to your vendor folder and in "/buchin/google-image-grabber/src/GoogleImageGrabber.php" show me the code from line 109 to 167.

numairawan avatar Oct 06 '22 17:10 numairawan

Go to your vendor folder and in "/buchin/google-image-grabber/src/GoogleImageGrabber.php" show me the code from line 109 to 167.

Below you'll find from 109 until the end of the file

`

    $rawResults = [];
    $results = [];

    if (isset($data[31][0][12][2])) {
        $rawResults = $data[31][0][12][2];
    }

    foreach ($rawResults as $rawResult) {
        $result = [];

        self::filterResult($rawResult, $result);
        $data = self::getValues($result);

        $result = [];

        if (count($data) >= 11) {
            $result["keyword"] = $keyword;
            $result["slug"] = __::slug($keyword);

            $result["title"] = isset($data[13])
                ? ucwords(__::slug($data[13], ["delimiter" => " "]))
                : "";
            $result["alt"] = isset($data[19])
                ? __::slug($data[19], ["delimiter" => " "])
                : "";

            $result["url"] = $data[8];
            $result["filetype"] = self::getFileType($data[8]);
            $result["width"] = $data[6];
            $result["height"] = $data[7];
            $result["source"] = isset($data[12]) ? $data[12] : "";
            $result["domain"] = isset($data[20]) ? $data[20] : "";

            $result["thumbnail"] = isset($data[26]) ? $data[26] : $data[1];

            if (strpos($result["url"], "http") !== false) {
                $results[] = $result;
            }

            $results[] = $result;
        }
    }

    return $results;
}

public static function getFileType($url)
{
    $url = strtolower($url);

    switch ($url) {
        case strpos($url, ".jpg") || strpos($url, ".jpeg"):
            return "jpg";
            break;

        case strpos($url, ".png"):
            return "png";
            break;

        case strpos($url, ".bmp"):
            return "bmp";
            break;

        case strpos($url, ".gif"):
            return "gif";
            break;

        default:
            return "jpg";
            break;
    }
}

} `

barbar-binks avatar Oct 06 '22 17:10 barbar-binks

I told you to update the repo to latest version. run composer update from your terminal to update it to latest.

numairawan avatar Oct 06 '22 17:10 numairawan

I told you to update the repo to latest version. run composer update from your terminal to update it to latest.

I am sorry, i suppose the update didn't go through, below you'll see what the composer.lock file has:

` { "name": "buchin/google-image-grabber", "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/buchin/google-image-grabber.git", "reference": "1e257f1b0aeaa17f9f4ea89d60f2e3f7707cb37f" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/buchin/google-image-grabber/zipball/1e257f1b0aeaa17f9f4ea89d60f2e3f7707cb37f", "reference": "1e257f1b0aeaa17f9f4ea89d60f2e3f7707cb37f", "shasum": "" }, "require": { "campo/random-user-agent": "^1.2", "maciejczyzewski/bottomline": "^0.0.9" }, "require-dev": { "kahlan/kahlan": "dev-master" }, "type": "library", "autoload": { "psr-4": { "Buchin\GoogleImageGrabber\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Mochammad Masbuchin", "email": "[email protected]" } ], "description": "Scrape google images", "support": { "issues": "https://github.com/buchin/google-image-grabber/issues", "source": "https://github.com/buchin/google-image-grabber/tree/1.0.3" }, "time": "2021-10-06T03:28:39+00:00" }

`

barbar-binks avatar Oct 06 '22 17:10 barbar-binks

As i said run composer update and it will update everything including this repo. If its still not work then clear your composer cache using command composer clear-cache or download this repo manually and replace your vendor GoogleImageGrabber.php with the one you downloaded.

numairawan avatar Oct 06 '22 18:10 numairawan

As i said run composer update and it will update everything including this repo. If its still not work then clear your composer cache using command composer clear-cache or download this repo manually and replace your vendor GoogleImageGrabber.php with the one you downloaded.

thank you, i did run composer update a bunch of times, even before continuing with the thread, also clearing the cache. I ended up doing the replacing of the GoogleImageGrabber.php manually.

it is working now, I appreciate the great work.

barbar-binks avatar Oct 06 '22 18:10 barbar-binks

Add on Composer JSON this:

`"require-dev": { ... "campo/random-user-agent": "^1.2", "maciejczyzewski/bottomline": "^0.0.9" }

"require-dev": { .... "kahlan/kahlan": "dev-master" }`

Later remplace content of GoogleImageGrabber.php with the github content.

Work for me.

cristophermr avatar Nov 02 '22 13:11 cristophermr