0

I am working on a little project with Curl and PHP to scrape the results of Google Scholar. It works fine in my development mode but when I try in a production mode something is not working and there is no result...

Here is my code:

// SCRAPING GOOGLE SCHOLAR
    if (isset($_POST['google'])){
        $googleURL = 'http://scholar.google.com/scholar?hl=fr&q=' . $url_subject;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $googleURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, $random->random_user_agent());
        $result = curl_exec ($ch);
        curl_close($ch);

        $html = $this->container->get('simple_html_dom');
        $html->load($result);

Thank you for your help

nico_lrx
  • 715
  • 1
  • 19
  • 36

1 Answers1

0

Google Scholar frowns on scraping their content. This is against their terms of service. Command line curl is helpful for troubleshooting this kind of thing:

$ curl -vv https://scholar.google.com/scholar?hl=en&q=neurotransmitters
> GET /scholar?hl=en HTTP/1.1
> User-Agent: curl/7.35.0
> Host: scholar.google.com
> Accept: */*
> 
< HTTP/1.1 403 Forbidden
...
<html>...<title>Sorry...</title></head><body>
<h1>We're sorry...</h1>
<p>... but your computer or network may be sending automated queries.
To protect our users, we can't process your request right now.</p>
<div style="margin-left: 4em;">See
<a href="https://support.google.com/websearch/answer/86640">Google Help</a>
for more information.</div>
</body></html>
Steve
  • 1,084
  • 11
  • 17