Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda