Python Forum
Fill out form on webpage and post request programmatically
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fill out form on webpage and post request programmatically
#1
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()
Reply
#2
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.
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Programmatically creating buttons that remember their positions Clunk_Head 6 1,273 Jun-22-2023, 02:51 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020