I've tried to use pyscript in html but i can only get it to work in one line of code can somebody help me get it to work for the following code?
def vpn(website):from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')driver = webdriver.Chrome(options=chrome_options)driver.get(website)vpn("chrome://newtab/")
The only code that I would even assume that would work is:
<!DOCTYPE html>
<html><pyscript>def vpn(website):from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')driver = webdriver.Chrome(options=chrome_options)driver.get(website)vpn("chrome://newtab/")</pyscript>
</html>
When I run said code, I get this error message:
def vpn(website): from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome(options=chrome_options) driver.get(website) vpn("chrome://newtab/")
Does anyone know any other way to do this?
Maybe, just maybe, there is an indentation problem. Pyscript code written inside html file will error if tab character is used for indentation even just once instead of spaces and the other way arround. It is hard to notice it as the code with tabs and with 4 spaces looks the same. Example:
<py-script>
import pandas as pd
data = {'A': [1, 2, 3, 4, 5], 'B': ['A', 'B', 'C', 'D', 'E']}
if data:
____df = pd.DataFrame(data)
____print('Print from index.html')
____print(df)
____pyscript.write('out', df)
</py-script>
This code above works ok because there are 4 spaces ( _ _ _ _ ) used for indentation. The code below ...
<py-script>
import pandas as pd
data = {'A': [1, 2, 3, 4, 5], 'B': ['A', 'B', 'C', 'D', 'E']}
if data:
____df = pd.DataFrame(data)
--->print('Print from index.html')
____print(df)
____pyscript.write('out', df)
</py-script>
... will cause an error because the command print('Print from index.html') is indented using tab (--->). In my case that tab indentation is set to 4 chars but just the fact that the tab is used instead of 4 spaces forces an error.
I don't write the pyscript code within the html file at all. Instead, I do it in the file and put it in the html as src attribute of pyscript tag.
The same code in that case is:
main.py file:
import pandas as pd
data = {'A': [1, 2, 3, 4, 5], 'B': ['A', 'B', 'C', 'D', 'E']}
if data:df = pd.DataFrame(data)print('Print from main.py')print(df)pyscript.write('out', df)
index.html file
...
<py-script id="outerPyMain" src="./main.py"></py-script>
...
In addition the "no tab char" rule is implemented within py-env tag too. To conclude, the indentation for pyscript tag should be always spaces or always tabs - no mixing allowed. For py-env tag it is just spaces.
Don't know if this is your case, but anyway...
Regards...