如何将值从PHP传递给Python,然后Python将返回该值并再次使用PHP输出

2024-04-25 07:33:24 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将值从php传递到python

<?php $print_this = "hello world";
//pass it to python. then echo it in here. "hello world";
?>

如何将一个变量的值从php传递给python,python将返回它,php将回显它。你知道吗

import sys
import urllib
from BeautifulSoup import BeautifulSoup as BS

url = '''http://www.kumby.com/avatar-the-last-airbender-book-3-chapter-5/'''
#open and read page
page = urllib.urlopen(url)
html = page.read()
#create BeautifulSoup parse-able "soup"
soup = BS(html)
#get the src attribute from the video tag


        video = soup.find("iframe").get("src")
        print video

变量url应该来自php。在php中

$url=网站

我的python代码应该是

url=$url

或者我不知道怎么做。我刚刚听说php可以调用python。所以我在想有没有可能把php的变量传递给python。你知道吗

现在变量video的值应该在php中得到响应。你知道吗


Tags: thefromimporturlhelloworldbsvideo
3条回答

你可以用管道:

php myscript.php | python myscript.py

您不需要Python,因为PHP有multiple ways来解析HTML/XML。你知道吗

下面是一个使用DOM extension的示例:

<?php

  $url = "http://www.kumby.com/avatar-the-last-airbender-book-3-chapter-5/";
  $page = new DOMDocument;
  $page->loadHTML(file_get_contents($url));
  foreach ($page->getElementsByTagName('iframe') as $node) {
    echo $node->getAttribute('src');
  }

?>

您可以使用$\u GET将变量发送到python脚本,并且python可以将值作为api返回。。。或者你可以在php中使用curl()

相关问题 更多 >

    热门问题