Hello im trying to run python script inside virtualenv from php but i cannot do it as well.
I wanna insert a Social network in my input php and i wanna get link in my php page
My php code and script python are in different folders
This is my php code:
<!DOCTYPE html>
<html>
<body>
<h1>Search Yahoo link</h1>
<form method="post" action="#">
<input type="text" name="social_network" placeholder="">
<input type="submit" name="Search" value="Go">
</form>
<?php
if (isset($_POST['Search'])) {
$item=$_POST['social_network'];
#$tmp = exec("python php_python.py $item"); This line it works if python script isnt in Virtual environment (Outside)
$tmp = exec("cd C:/Users/admin/Desktop/python venv\scripts\activate.bat python yahoo.py $item");
echo $tmp;
}
?>
</body>
</html>
Python code:
from selenium import webdriver
import time, sys
social_network = int(sys.argv[1]) # will receive values like: Facebook, Instagram, twitter, etc
driver= webdriver.Chrome()
driver.get('https://espanol.yahoo.com/?p=us')
#Search Social Network
driver.find_element_by_xpath('//*[@id="uh-search-box"]').send_keys(social_network)
driver.find_element_by_xpath('//*[@id="uh-search-button"]').click()
time.sleep(5)
link = driver.find_element_by_xpath('//*[@id="web"]/ol/li[2]/div/div[1]/div/span[1]').text
print(link)
driver.quit()