Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 660
Baz Avatar asked Mar 21 '23 22:03

Baz


1 Answers

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

like image 162
TimStuart Avatar answered Apr 01 '23 05:04

TimStuart