Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
Would it be possible to open a website and then run JavaScript in it using Python?

I have been trying to open a website (using python), then run a JavaScript script on it.

I did the open the website part, but I haven't managed to get the JavaScript to run after the page loads.

import os
url='example.com'
jscode='alert(\'success\')'
os.system('start chrome.exe '+url+' javascript:'+jscode)

The code above is the best I can think of.

It opens the website but does not run the javascript.

I used os.system() because other methods have problems with chrome.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I figured it out:

VBScript and batch together to open the site then enter keystrokes

'https://www.codegrepper.com/code-examples/whatever/Make+a+batch+file+that+opens+site+in+browser+and+enter+login+information' was very useful for developing this answer

'''
enclosed in '{}' means special characters

'~' or '{ENTER}' = [ENTER]
'^' = [CTRL]

multiple characters in the same list item are typed at the same time
'''

keyplan = ["^l","javascript:alert{(}'success'{)}","~"]

with open('temp.cmd','w') as f: pass
with open('temp.cmd', 'a') as f:
    #batch code section
    f.write(
     '@if (@CodeSection == @Batch) @then\n'
    +'@echo off\n'
    +'set SendKeys=CScript //nologo //E:JScript "%~F0"\n')
    +'START CHROME "example.com"\n'
    +'timeout /t 10\n'
    )#the timeout is to give time for the page to load
    
    #log keys in plan
    for key in keyplan:
        f.write('%SendKeys% "'+key+'"\n')
    
    f.write('goto :EOF\n')
    f.write('@end\n')
    
    #VBScript section
    f.write('var WshShell = WScript.CreateObject("WScript.Shell");\n')
    
    #send keys (runs on every '%SendKeys% "key")
    f.write('WshShell.SendKeys(WScript.Arguments(0));\n')
os.system("temp.cmd")

After writing this I have realized that import pynput is a method that would not involve os.system.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda