I was making an python program that executes a java script after loading a webpage it is a web based api where we can execute javascript commands through console of your browser (f12) ( api documentation)
This executing gives back an array, I just want to get this output of execution (the array) to be print. the code i used is given below. the time delay of 15 seconds is used for solving an captcha which have to do manually.
executing getPlayerList(); command will give back you a list of players that is currently playing.
from selenium import webdriver
import time
import os
driver=webdriver.Firefox()
driver.get("https://html5.haxball.com/headless")
time.sleep(5)
driver.execute_script("""
window.room = window.HBInit({ roomName: 'botts', maxPlayers: 16 });
""")
#the time dalay is to solve the captcha manually that appear on the browser after executing above javascript.
time.sleep(15)
print(driver.execute_script("""
console.log(window.getPlayerList();
"""))
The above program works fine, but i have to print the output of getPlayerList(); I tried with return and console log, but that is not working for me.
getPlayerList()?getPlayerList()is a function that's defined in the webpage you're scraping. You can't use functions that aren't defined within the scope of your code.