Search code examples
phppythonweb-scrapingscrapyscrapyd

Invoke scrapy script from PHP/HTML or webserver


I have a scrapy script which will run multiple spiders. I want to crawl the single spider or run the multiple spider script from PHP/HTML code. Is that possible? If so, how?


Solution

  • Try this in PHP:

    Add this line in your python script:

    #!/usr/bin/env python
    

    Make the script executable:

    chmod +x myscript.py
    

    Execute the file using something like this:

    <?php 
    
    $command = escapeshellcmd('/home/myscript.py');
    $output = shell_exec($command);
    echo $output;
    
    ?>