如何在python中使用php脚本

I am trying to write some code for a project in python 3.5. I have an API script which is written in php. I want to use this script in my python code. I am looking for a way but I could not find one yet.

Here is my python code:

#Loading Libraries
import urllib
import os
import time
from urllib.parse import urlparse
from urllib.parse import urljoin
from collections import Counter
import urllib.request

from bs4 import BeautifulSoup
id= 1
url='http://scitechdaily.com/new-technique-reveals-internal-characteristics-of-photonic-crystals/'

    
def GetArticles(url,id):
    file = open('C:\\Users\\Hassan Raza\\Desktop\\Mozilla tech article\\Article'+'.txt', 'w')
    req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
    
    htmlpage = urllib.request.urlopen(req)
    html = htmlpage.read().decode('utf-8')

    soup = BeautifulSoup(html,"html.parser")

    title= soup.find_all('h1', {'class','title'})
    for titles in title:
        print(titles.text)
    text = soup.find_all('div' , {'class', 'entry'})
    for pg in text:
        textdata = pg.text.encode('utf8')


        ############ Here I want to pass textdata to an API which is wirtten in PHP##########################
        
        
    file.close()
    
GetArticles(url,id)

Please let me know how to use a php script in python so I can compete my project.

</div>

You add PHP script and execute the script using python

import subprocess

# if the script don't need output.
subprocess.call(["php", "/path/to/your/script.php"])

# if you want output
proc = subprocess.Popen("php /path/to/your/script.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()

Yes that's possible.

$ cat test.py
import subprocess

print subprocess.Popen(['php', '-f', 'test.php'])
$ cat test.php
<?php
ini_set("allow_url_fopen", 1);

$url = "https://baconipsum.com/api/?type=all-meat&paras=2&start-with-lorem=1";

$json = file_get_contents($url);
$obj = json_decode($json);

print_r($obj);
$ python test.py
<subprocess.Popen object at 0x7f968fcefd90>
$ Array
(
    [0] => Bacon ipsum dolor amet frankfurter beef ribs jowl alcatra kielbasa pork loin andouille.  Filet mignon pork chop bacon brisket meatball, strip steak picanha kielbasa tri-tip pork capicola boudin leberkas.  Tail spare ribs cow sirloin, pancetta ribeye capicola flank porchetta prosciutto pork pastrami.  Burgdoggen turducken meatball, hamburger salami bacon drumstick bresaola strip steak fatback boudin ham.  Filet mignon fatback bresaola landjaeger brisket, tri-tip flank pork belly sirloin venison.  Sausage biltong turducken pork chop turkey cow meatball bacon shankle drumstick.  Jerky cow shankle pork loin tongue ribeye leberkas landjaeger spare ribs prosciutto capicola alcatra tenderloin.
    [1] => Beef fatback frankfurter alcatra chuck ribeye.  Shankle corned beef kielbasa frankfurter bacon jerky, flank sirloin kevin ball tip burgdoggen hamburger pork belly tongue rump.  Short ribs pastrami hamburger, shank chuck short loin strip steak pork loin filet mignon sausage.  Leberkas pork loin jowl burgdoggen frankfurter pork belly.  Tongue fatback jowl ribeye.  Meatball bresaola spare ribs cupim rump pork belly tenderloin frankfurter shank picanha jerky bacon t-bone.  Pork belly spare ribs filet mignon, ground round meatball pancetta pastrami bacon pig ribeye ham frankfurter leberkas.
)