Python Forum
Fill out form on webpage and post request programmatically - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Fill out form on webpage and post request programmatically (/thread-4026.html)



Fill out form on webpage and post request programmatically - ian - Jul-18-2017

I am working on the following code. what I need next is to fill something in the search box and click 'Google Search' button to go next page in python code, not manually input and click the button.
wx.html2 webview can launch webpage in wx.Panel, that is what I need. But it seems cannot fill and post request. Any other modules can do it? Thanks.


import wx
import wx.grid
import wx.html2 as webview

class LeftPanel(wx.Panel):
   def __init__(self, parent):
       wx.Panel.__init__(self, parent=parent)
       self.current = "https://www.google.com"
       self.frame = self.GetTopLevelParent()
       self.titleBase = self.frame.GetTitle()
       sizer = wx.BoxSizer(wx.VERTICAL)
       self.wv = webview.WebView.New(self)
       sizer.Add(self.wv, 1, wx.EXPAND)
       self.SetSizer(sizer)
       self.wv.LoadURL(self.current)
class RightPanel(wx.Panel):
   def __init__(self, parent):
       wx.Panel.__init__(self, parent=parent)
       self.grid = wx.grid.Grid(self, size=(278, 150), pos=(0,0))
       self.grid.CreateGrid(5,20)
class Frame(wx.Frame):
   def __init__(self):
       wx.Frame.__init__(self, None, title="Search", size=(1600, 860), pos = (0, 0))
       splitter = wx.SplitterWindow(self)
       splitter.SetMinimumPaneSize(1000)
       splitter.SplitVertically(LeftPanel(splitter), RightPanel(splitter))
if __name__ == "__main__":
   app = wx.App()
   win = Frame()
   win.Show()
   app.MainLoop()



RE: Fill out form on webpage and post request programmatically - Larz60+ - Jul-18-2017

Please visit https://python-forum.io/misc.php?action=help and re-post code correctly using tags and proper indentation.

Anyone here will be glad to help after that.


RE: Fill out form on webpage and post request programmatically - ian - Jul-18-2017

Sorry, forgot indentation. This code works and next step I need to add some code to be able to navigate webpage, e.g. on this Google search: fill some words in search box and submit the request to get results on next page. or another example: launch a logon webpage, fill in id/password and submit to logon. Thanks.


import wx
import wx.grid
import wx.html2 as webview

class LeftPanel(wx.Panel):
   def __init__(self, parent):
       wx.Panel.__init__(self, parent=parent)
       self.current = "https://www.google.com"
       self.frame = self.GetTopLevelParent()
       self.titleBase = self.frame.GetTitle()
       sizer = wx.BoxSizer(wx.VERTICAL)
       self.wv = webview.WebView.New(self)
       sizer.Add(self.wv, 1, wx.EXPAND)
       self.SetSizer(sizer)
       self.wv.LoadURL(self.current)


class RightPanel(wx.Panel):
   def __init__(self, parent):
       wx.Panel.__init__(self, parent=parent)
       self.grid = wx.grid.Grid(self, size=(278, 150), pos=(0,0))
       self.grid.CreateGrid(5,20)


class Frame(wx.Frame):
   def __init__(self):
       wx.Frame.__init__(self, None, title="Search", size=(1600, 860), pos = (0, 0))
       splitter = wx.SplitterWindow(self)
       splitter.SetMinimumPaneSize(1000)
       splitter.SplitVertically(LeftPanel(splitter), RightPanel(splitter))


if __name__ == "__main__":
   app = wx.App()
   win = Frame()
   win.Show()
   app.MainLoop()