Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
Return the Link of first result in google search in PHP

I want to return the first URL of google search result like: First Url Result

Google search

.php code:

<?php
        //Check if submit button is clicked or not
        if (isset($_POST['submit'])) {
            $text = $_POST['text'];
            // echo $text;

            function file_get_contents_curl($url) {
                $ch = curl_init();
            
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
                curl_setopt($ch, CURLOPT_URL, $url);
            
                $data = curl_exec($ch);
                curl_close($ch);
            
                return $data;
            }
            
            $query =  $text;
            $url = 'http://www.google.co.in/search?q='.urlencode($query).'';
            echo $url;
            $scrape = file_get_contents_curl($url);
            echo $scrape;
?>

How can i achieve that?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

By default since using this scraping method only sends an HTTP request and does not run render page as browsers do, google won't load you the page you are looking for and it will show you an agreement page like this. enter image description here

You should use the google Search API as mentioned by ADyson in the comment

Another approach which is not recommended is that you use selenium or any headless browser. Using the headless browser you will still be prompt by agreement but behind it you can scrape the search results. enter image description here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda