Solved

Videos on google first page

Posted on 2016-09-15
10
37 Views
Last Modified: 2016-09-16
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.
0
Comment
Question by:JayDip Dev
  • 5
  • 5
10 Comments
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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.
1
 

Author Comment

by:JayDip Dev
Comment Utility
Hi,

I have try

substr_count( $str, 'vidthumb' );

Open in new window


But it not work.
0
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
If possible, post full source code you're working on right now.
0
 

Author Comment

by:JayDip Dev
Comment Utility
$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
0
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
Needed to rework something again (as I said, mostly because of Javascript vs source code).
Obviously, remove the two echo lines for the real result. Right now, it's there so you can verify if the results is true.

<?php

$google_url = "https://www.google.nl/search?client=opera&q=free+how+to+video+episode&sourceid=opera&ie=UTF-8&oe=UTF-8";

$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_URL, $google_url );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

echo '-----';

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

echo $google_vid;

?>

Open in new window

1
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:JayDip Dev
Comment Utility
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.
0
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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.
0
 

Author Closing Comment

by:JayDip Dev
Comment Utility
Yes, You are right, it works now.

Thanks a Lot ...
0
 

Author Comment

by:JayDip Dev
Comment Utility
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
0
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now