[英]how to pass value from php to python and the python will return the value and echo it using php again
How to pass a value from php to python 如何将值从php传递到python
<?php $print_this = "hello world";
//pass it to python. then echo it in here. "hello world";
?>
how will i pass the value of a variable from php to python and the python will return it and the php will echo it. 我如何将变量的值从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
the variable url should come from the php. 可变网址应来自php。 where in php ,
在php中,
$url = website $ url =网站
and in that my python code should be 在那我的python代码应该是
url = $url 网址= $ url
or i dont know how. 或者我不知道怎么做。 i just heard that the php can call the python.
我只是听说php可以调用python。 so i was thinking is it possible to pass the variable of php to python .
所以我在想是否有可能将php的变量传递给python。
now the value of variable video should be echoed in php. 现在,可变视频的值应在php中回显。
您可以通过管道发送它:
php myscript.php | python myscript.py
您可以使用$ _GET将变量发送到python脚本,并且您的python可以将值返回为api ...或者您可以在php中使用curl()
You do not need Python as PHP has multiple ways to parse HTML/XML. 您不需要Python,因为PHP具有多种解析HTML / XML的方法。
Here is an example using the DOM extension : 这是使用DOM扩展的示例:
<?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');
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.