populate html form using python and open in browser without submitting - python

I am trying to write a python script that populates the fields of an html form and then opens that form in a browser WITHOUT submitting it.
I can fill the form and submit it using URllib and urllib2 however I dont want to submit it - I want the person to check the data and then submit it manually.
I have seen this might be possible with Mechanize or Selenium but I want to try and do this with what comes standard (the script will be run on various computers by people who don't know what python is...)
Does anyone know how I could do this?

Opens the form in the browser? This will be tricky, as there is no cross-platform way to open a browser and point it to a URL. On Linux you would probably use xdg-open, on Windows I believe you can just use start, and I have no clue on Mac OS X. But regardless, you would use the subprocess module to open a web browser.
As for the filling it out part...you might be able to replicate the page and serve the local, pre-filled copy with a basic webserver, shutting it down when the user submits the form. I don't think this would be the best idea.
An alternative is using Sikuli script to automate everything - open the user's web browser, populate the fields, maybe even move the mouse cursor to the submit button or highlight it without clicking. That sounds more like what you're trying to achieve.

Related

Python interact with webrowser (opend by a user)

I am searching for a way which allows me to interact with a webrowser (Firefox,Chrome/Chromium,Edge are the most important).
I am currently using pyautogui, to locate login,password fields to put the login data into them. But since you can extract much easier informations when you can use IDs or xPath or other identifiers on webpages, it would make sense to use that.
I tried Firefox with selenium but I run in some problems. Can I attache it to a user created session (do I need the processID or something like that?). (Can I choose between the normal private session of the current profile?
I need a solution which works on Windows and Linux(it would be nice if the major Linux distros would support it. But the most important distros are Fedora/Ubuntu for me.) mac would be optional but since I do not got any mac I am not able to test it anyway.
The way with debugger mode or similar does not work really well for me since the browser needs to get started in a special way.
Would it possible to use something like this:
Can Selenium interact with an existing browser session? ,
When I can retrieve the this information some how form the existing browser?
driver.command_executor._url
driver.session_id
(But when I understand that currently it only works with browsers started with selenium?)
When I use Selenum and start a browserwindow with it can I login to a website and the user is logged in on the webside on his browser window too(if they us the same profile)? (Or does selenium separate cookies?)
If you need additional information or have some hints please post them so I can see them.
Thank you in advance for your help
It seems that it is not possible to connect to a web browser which was opened by the user to my understanding. How ever I found two possible solutions which I am currently trying to evaluate.
Using pyautogui to access the web browser over scanned images and control it with keyboard and mouse. (It is possible to access the console with the right combinations too).
The other solution is maybe more stable. Writing an browser extension which controls the browser.

Use Existing Google Chrome Window To Web Scrape Python

Running Python 3.6 and I'm having a whole lot of issues logging to a site primarily due to captcha. I really only need to search up URLs and retrieve the html on the page but I need to be logged in for certain additional information to appear on the accessible URLs.
I was using urllib to read the URLs but now I was looking for a solution to login and then request information. The automatic route won't seem to work due to those issues, so I'm looking for a method by which I am already logged in on an open browser and python opens up new tabs to search for URLs (the searches can be hidden, they don't have to literally open up new tabs). It appears that when I open new tabs manually on the site it still shows i'm logged in so If i can manually log in each time i want to run the script and then work based off that, it would actually work just fine.
Thanks

Automate browser interaction

I need to upload hundreds of files via a html form, so that they end up on a server. I have no other options and must go via the form.
I have tried doing this problematically using python but I'm doing something wrong and the files are empty when I try to open them via the web interface. I also tried doing a replay via firefox's TamperData and the file is also uploaded incorrectly in this case.
So I'm interested in exploring the idea of uploading the files by automating my browser instead. All I need to do is:
for file in files:
open a page
click on the browse button
select a file
click the upload button
So what software/library can I use to do this? I don't necessarily need to do this using python as I will never need to do this again in the future. I just need to get the files up there by any means possible.
I have access to Windows 7, Mac Os X, and Suse Linux.
I also don't care which browser I use.
Splinter works well for this kind of thing:
https://github.com/cobrateam/splinter
You could do something like:
from splinter import Browser
with Browser('firefox') as browser:
browser.visit('http://yourwebsite.com')
browser.find_by_name('element_name').click()
do some other stuff...
You just need to find the name or ID of the element you want to interact with on the page
please check out selenium:
It's an automated browser tool (behaves like a real user)
http://selenium-python.readthedocs.org/en/latest/
You can also if you're more the techy type and understand html write your own python code to only send files to the server with httplib2
https://code.google.com/p/httplib2/
for an auto clicker try autopy (this emulates mouse and keyboard input)
http://www.autopy.org/

How to control and interact with elements on a webpage displayed with IE or a different browser with pywinauto

I want to be able to access the elements of a webpage with python. I use Python 2.5 with Windows XP. Currently, I am using pywinauto to try to control IE, but I could switch to a different browser or module if it is needed. I need to be able to click the buttons the page has and type in text boxes. So far the best I've gotten is I was able to bring IE to the page I wanted. If it is possible without actually clicking the coords of the buttons and text boxes on the page, please tell me. Thanks!
I think for interacting with webserver better is to use cUrl. All webservers function are responses for GET or POST request (or both). in order to call them, just call the urls that buttons are linked to and/or send POST data attaching that data to appropiate request obj before calling send method. cUrl is able to retrieve and do some processing on webserver responce (web site code) without displaying it, what delivers knowledge about url adresses contained in the web site, which are called when clicking certain buttons. Also possible to know html fields which carry POST data to get their names.
Python has curl lib, which I hope is so powerful as PHP curl, tool what I used and presented.
Hope you are on the track now.
BR
Marek
Tommy ,
What i Have observer till now if u have a web application and if u are able to identify the object in that page using winspy (tool for spyup the controls in the page). you can automate that. Else you cant.
Like using following code
app = Application.Application();
app.window_(title_re = 'Internet Explorer. *').OKButton.Click()

python web script send job to printer

Is it possible for my python web app to provide an option the for user to automatically send jobs to the locally connected printer? Or will the user always have to use the browser to manually print out everything.
If your Python webapp is running inside a browser on the client machine, I don't see any other way than manually for the user.
Some workarounds you might want to investigate:
if you web app is installed on the client machine, you will be able to connect directly to the printer, as you have access to the underlying OS system.
you could potentially create a plugin that can be installed on the browser that does this for him, but I have no clue as how this works technically.
what is it that you want to print ? You could generate a pdf that contains everything that the user needs to print, in one go ?
You can serve to the user's browser a webpage that includes the necessary Javascript code to perform the printing if the user clicks to request it, as shown for example here (a pretty dated article, but the key idea of using Javascript to call window.print has not changed, and the article has some useful suggestions, e.g. on making a printer-friendly page; you can locate lots of other articles mentioning window.print with a web search, if you wish).
Calling window.print (from the Javascript part of the page that your Python server-side code will serve) will actually (in all browsers/OSs I know) bring up a print dialog, so the user gets system-appropriate options (picking a printer if he has several, maybe saving as PDF instead of doing an actual print if his system supports that, etc, etc).

Categories

Resources