I have a running loop script in Python, which I want interact with a HTML-page. For example:
(HTML)Clicking button -> magic -> (Python) Do something function in script.py
This response is not appropriate for this.
I have a running loop script in Python, which I want interact with a HTML-page. For example:
(HTML)Clicking button -> magic -> (Python) Do something function in script.py
This response is not appropriate for this.
Probably you can use Selenium python binding for the purpose of interecting with Web page with your python script.
Example:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
I resole this problem by PIPE in python. Python script reads file p1.txt by line and server.js sends text. For example, here server.js sends string 'COMMAND' and we are getting script.py response.
script.py
import os,sys
fd = "./p1.txt"
try:
os.mkfifo(fd)
except OSError:
pass
rp = os.open(fd, os.O_RDONLY)
#Need to create new thread, for background reading file
while True:
response = os.read(rp, 54)
if response == "COMMAND":
#do
print 'ICATCHYOU'
server.js
var fs = require('fs');
var path = '/home/pi/develop/p1.txt';
var streamOptions = { flags: 'w',
encoding: 'utf-8',
mode: 0666 };
var afterOpen = function(err, fd) {
var writeStream = fs.createWriteStream(path, streamOptions);
writeStream.write("COMMAND");
};
fs.open(path, 'w', afterOpen);