pythonlaravelweb-scrapinggoutte

How to send a variable from Laravel Controller to a Python script?


$client = new Client();
$a = 'https://scholar.google.com/citations?user=';
$gscID = 'EnegzCwAAAAJ';//for eg
$b = '&hl=en&oi=ao';
$url = $a . $gscID . $b;

$crawler = $client->request('GET', $url);

//python script
$process = new Process(['python', public_path() . '\ext.py'], null, ['SYSTEMROOT' => getenv('SYSTEMROOT'), 'PATH' => getenv("PATH")]);
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}
$out[] = $process->getOutput();
dd($out);

Extracting the tables from the given url webpage

Now I want to pass the $url variable to the python script stored in my public folder because everytime my url changes with different person's ID.

Any help would be really appreciated


Solution

  • Found out an easy solution $output = shell_exec("python ext.py $url");//ext.py is name of my script and $url is my variable which I want to pass

    And then in python script write

    import sys
    url = sys.argv[1]