Avatar of JayDip Dev
JayDip Dev
 asked on

Videos on google first page

Hi,

There is any way to get number of videos on first page of google by any custom script or API, when we search by a keyword in google?

For e.g. if I am searching with "jquery tutorial" keyword in google, I can see one video on google search result page so it should return 1, same for other keywords.

Thanks.
PHP

Avatar of undefined
Last Comment
Kimputer

8/22/2022 - Mon
Kimputer

Enumerate all "vidthumb" on the source, then count unique (since source code may contain two instances of vidthumb1, and two instances of vidthumb4. Still totals 2 videos)
I have no idea why they jump in numbers.
JayDip Dev

ASKER
Hi,

I have try

substr_count( $str, 'vidthumb' );

Open in new window


But it not work.
Kimputer

If possible, post full source code you're working on right now.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
JayDip Dev

ASKER
$google_url = "https://www.google.com/search?q=jquery+tutorial";

$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_URL, $google_url );
$result = curl_exec($ch);
curl_close($ch);

$google_vid = 0;
//$google_vid = substr_count( $result, 'https://www.youtube.com/watch' );
$google_vid = substr_count( $result, 'vidthumb');

echo $google_vid;

Open in new window


Output is: 0
ASKER CERTIFIED SOLUTION
Kimputer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
JayDip Dev

ASKER
I have tried with "web design tutorial" keyword with same code that you given and applied it to here: http://slmp-550-4.slc.westdc.net/~web/google-api/

It give me 1 video as a result instead of 2, please check and suggest.
Kimputer

The result is 1, it's correct. If you see two, it means you're checking with your browser which contains cookies and therefore has different results.
You have to use my original code INCLUDING the test echo's to double check.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
JayDip Dev

ASKER
Yes, You are right, it works now.

Thanks a Lot ...
JayDip Dev

ASKER
Hi,

I have got new issue with this method it gives me error from google:

Our systems have detected unusual traffic from your computer network.  This page checks to see if it's really you sending the requests, and not a robot.

please suggest

Thanks
Kimputer

Even if I do hundreds of Google searches in my browser, it won't trip up the system. It probably means you really are doing thousands if not millions of these requests (I saw one search does multiple searches already based on auto complete suggestions?)?
Check this page for more on it:
https://support.google.com/websearch/answer/86640?hl=en

If you are really doing automated searches, instead of human initiated ones (and therefore, much lower volume), you really have a problem. Maybe add some detection mechanism, and maybe you'll be able to temporarily continue searching by opening a Google search on a browser (on the same computer or other computer inside the network), and filling in the CAPTCHA.
If you don't change ANYTHING at all (same volume of searches), this cycle will continue at the same rate, there's no real way to stop it from happening.
If it's really important you get the results, maybe take a look here: https://www.google.com/work/search/products/gss.html#pricing_content
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck