I am looking for a way to obtain a Python list and display it on my website using PHP.
I've checked out and tried many online help-requests so I was hoping someone would be able to explain to me what it is I am doing wrong.
My Python script scrapes a website and puts the result in a Python list.
What I am trying to achieve is the following:
- I want to display (a part) of the list on my website.
I've tried to accomplish this with the following code:
PHP
<?php
$outputArray = [];
$returnStatus;
exec('python ./scrapeWebsite.py', $outputArray, $returnStatus);
var_dump($outputArray);
echo $returnStatus;
?>
Python:
print(newsHeadlines) -> returning a list like this: ['item 1','item 2','item 3','item 4']
However, the array comes back as array(0) { } and the $returnStatus value is 1.
execcall is a string, not an array. So store the result in a string, then use PHP to cut it and make it an array, if you must (hint, PHP explode).