Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopped Grabbing Results #18

Open
barbar-binks opened this issue Sep 26, 2022 · 17 comments
Open

Stopped Grabbing Results #18

barbar-binks opened this issue Sep 26, 2022 · 17 comments

Comments

@barbar-binks
Copy link

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?

@ericbae
Copy link

ericbae commented Sep 27, 2022

It's still working for me.

@numairawan
Copy link
Contributor

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

@barbar-binks
Copy link
Author

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

I will do that, thank you very much.

@barbar-binks
Copy link
Author

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.

@numairawan
Copy link
Contributor

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

@barbar-binks
Copy link
Author

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
Copy link
Author

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

@numairawan
Copy link
Contributor

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;
}

@barbar-binks
Copy link
Author

barbar-binks commented Oct 6, 2022

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
Copy link
Author

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

@numairawan
Copy link
Contributor

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

@barbar-binks
Copy link
Author

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;
    }
}

}
`

@numairawan
Copy link
Contributor

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

@barbar-binks
Copy link
Author

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"
}

`

@numairawan
Copy link
Contributor

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.

@barbar-binks
Copy link
Author

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.

@cristophermr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants