$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 :
strong textTo send a variable from a Laravel controller to a Python script, you can use the shell_exec() function in PHP to execute the Python script and pass the variable as an argument.
First, in your Laravel controller, you can define the variable and pass it to the shell_exec() function as an argument. For example, let’s say you have a variable called $variable that you want to send to a Python script called script.py. You could use the following code to execute the script and pass the variable to it:
Copy code
$output = shell_exec("python script.py $variable");
This code will execute the script.py script and pass the value of $variable as an argument. The output of the script will be stored in the $output variable.
Next, in your Python script, you can access the argument passed from the Laravel controller by using the sys module in Python. The sys module provides access to the arguments passed to the script, which are stored in a list called sys.argv. You can access the first argument (i.e. the variable passed from the controller) using the following code:
Copy code
import sys
variable = sys.argv[1]
This code will import the sys module and then access the first element in the sys.argv list, which will be the value of the variable passed from the controller. This value will be stored in the variable variable, which you can then use in your script.
I hope this helps! Let me know if you have any other questions.