S
S
Seganapa2012-11-14 08:30:41
Python
Seganapa, 2012-11-14 08:30:41

How to enter username and password programmatically?

There is this code:

#coding:utf-8

import wx
import sys
import time
import cefpython

class MainFrame(wx.Frame):

    browser = None

    def __init__(self):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title='wxPython example', size=(1000,800))
        self.browser = cefpython.CreateBrowser(self.GetHandle(), browserSettings={}, navigateURL="http://ru.grepolis.com")        
        

class MyApp(wx.App):
    timer = None
    timerID = 1

    def OnInit(self):
        cefpython.Initialize()
        sys.excepthook = cefpython.ExceptHook

        self.timer = wx.Timer(self, self.timerID)
        self.timer.Start(10) # 10ms
        wx.EVT_TIMER(self, self.timerID, self.OnTimer)
        
        frame = MainFrame()
        self.SetTopWindow(frame)
        frame.Show()
        
        return True

    def OnTimer(self, event):

        cefpython.SingleMessageLoop()

app = MyApp()
app.MainLoop()

It opens the Grepolis online game page.
I specially created a test ACC:
Login: Sudorei
Password: 26102012
How can I programmatically pass authorization?
The developer says that it is possible with the help of JavaScript, but I don’t understand exactly how ... How to connect?
Help me please…

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nochkin, 2012-11-14
@nochkin

The login and password are transmitted by the form either via POST (most often) or via GET.
It is enough to see which fields are passed during login and pass the same ones in the script.
Specifically, with cefpython, I won’t tell you how to do this, but, for example, try using navigateURL.
Although, if you look at the cefpython documentation, it was cool to use SendKeyEvent, SendMouseClickEvent and something like that, but the module is still quite raw and such chips have not yet been made there.

S
Seganapa, 2012-11-14
@Seganapa

Are there people here who know JavaScript? I need help only in this matter ... How to programmatically enter data and click two buttons ... Is it really necessary to learn all JavaScript because of this, I, so to speak, only know Python for half a year ... I still have to study and study here ...

S
Sergei Borisov, 2012-11-14
@risik

There are other options: watin, watir, watij. Well, this is if python and javascript are not the only possible option for you

S
Seganapa, 2012-11-21
@Seganapa

Please help someone sort this out.
Created HTML with text string for example:

code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Textovoe Pole</title>
</head>
<body>

<form action="/cgi-bin/handler.cgi">
<p><b>Text</b></p>
<p><input type="text" maxlength="25" size="20"></p>
</form>

</body>
</html>

Here is the cefpython code that loads this HTML:
# Simple CEF Python application, 
# for more advanced features see "cefadvanced.py"

import cefpython
import cefwindow
import win32con
import win32gui
import win32api
import sys
import os

def CloseApplication(windowID, message, wparam, lparam):
  browser = cefpython.GetBrowserByWindowID(windowID)
  browser.CloseBrowser()
  return win32gui.DefWindowProc(windowID, message, wparam, lparam)

def QuitApplication(windowID, message, wparam, lparam):
  win32gui.PostQuitMessage(0)
  return 0

def CefSimple():
  sys.excepthook = cefpython.ExceptHook
  cefpython.Initialize()
  wndproc = {
    win32con.WM_CLOSE: CloseApplication, 
    win32con.WM_DESTROY: QuitApplication,
    win32con.WM_SIZE: cefpython.wm_Size,
    win32con.WM_SETFOCUS: cefpython.wm_SetFocus,
    win32con.WM_ERASEBKGND: cefpython.wm_EraseBkgnd
  }
  windowID = cefwindow.CreateWindow(title="CefSimple", className="cefsimple", 
          width=800, height=600, icon="icon.ico", windowProc=wndproc)
  browser = cefpython.CreateBrowser(windowID, browserSettings={}, navigateURL="new_2.html")
  cefpython.MessageLoop()
  cefpython.Shutdown()

if __name__ == "__main__":
  CefSimple()

Where do you need to insert
Browser->GetMainFrame()->ExecuteJavascript("document.getElementById('lst-ib').value='my search';")
to get the value in the text field???

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question