javascript - Splinter: How to pass argument to execute_script? -
i need execute javascript function on page, passing array of strings. want avoid having phone call browser.execute_script
number of times.
list_of_strings = ['a','b','c'] #js code runs through strings result = browser.execute_script("function findtexts(textlist){//code here}", list_of_strings)
dump python list json
, utilize string formatting:
import json json_array = json.dumps(list_of_strings) result = browser.execute_script("function findtexts(%s){//code here}" % json_array)
here's js code produce:
>>> import json >>> list_of_strings = ['a','b','c'] >>> json_array = json.dumps(list_of_strings) >>> "function findtexts(%s){//code here}" % json_array 'function findtexts(["a", "b", "c"]){//code here}'
javascript python splinter
No comments:
Post a Comment