Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to build a bot to automate web browsing, this mean something like:

  • filling forms
  • press "submit" buttons
  • find certain text inside pages
  • and so on...

How can I do this with Mathematica?

The Import function just make you download a single web page but it doesn't support cookies and similar things to build a complete automated bot, does Mathematica have some useful packet to do so?

share|improve this question
    
If the form uses the GET method, submitting the form just means composing an URL (on which Import works). The question is very general in this form, and I'd be inclined to say Mathematica is not the right tool for this (you'll end up using JLink or .NETLink anyway). But if you can give a very specific example, we can think about how to implement it in Mathematica (or will be able to say with more confidence that it's not possible without external libraries) –  Szabolcs Feb 15 '12 at 10:32
    
Yes, I know that for a GET method I can simply compose the URL in the right way. I give you an example: suppose I want to make a little script to log-in to an online service, put some informations in a form to generate a report, download the report and then use Mathematica to analyze this, and I want to do it "one-click", without make the log-in and download manually! –  Francesco Feb 15 '12 at 10:39
    
I don't believe that this is possible in pure Mathematica. Any working solution you might get will use external libraries, most likely through either JLink or .NETLink. You might be able to drive a browser object through .NETLink on Windows, but I am not familiar with the technology. –  Szabolcs Feb 15 '12 at 10:43
2  
if you need support for cookies then use wget. You can include it in Mma code by using Run. About to go to bed but do a search cause posted something here in answer to another question a couple of weeks ago. ...here it is: mathematica.stackexchange.com/questions/1186/… –  Mike Honeychurch Feb 15 '12 at 11:26
3  
You can also try curl: stackoverflow.com/a/6977128/695132 –  Szabolcs Feb 15 '12 at 12:08

1 Answer 1

Here is a package which I think does what you want:

http://www.wolframcloud.com/objects/user-7053ce31-817f-4643-aec1-eda27051bba6/WebUnit.zip

Download the file, and unzip it, and place the WebUnit folder under $UserBaseDirectory/Applications

To use it:

  1. Needs["WebUnit`"]

  2. InstallWebUnit[] (* launches chromedriver.exe *)

  3. StartWebSession[] (* launches Chrome web browser, assuming you have that installed *)

  4. OpenWebPage["http://mathematica.stackexchange.com"] (* opens the web page *)

  5. ClickElement[Id["nav-users"]] (* clicks the web element 'nav-users' the users tab *)

And then TypeElement works similarly (assuming you have an input field with an id).

Edit: You can also use JavascriptExecute["alert('hi');"] to execute arbitrary javascript (in this example case it brings up the alert dialog).

share|improve this answer
2  
Great application! But could you provide a WebUnit documentation in a pdf file? On my computer the provided documentation does not open properly. I am not sure whether the directory structure in the provided bundle is OK. BTW: is it possible to set a value to a RadioButton? –  jano Dec 23 '14 at 22:49
    
@Arnoud Buzing Can you provide a minimal example of how to use Execute[] to run some javascript? I can find this function in the WebUnit source code. There is no documentation so I am asking you here. –  PlatoManiac Jan 6 at 4:30
    
This works for me: Execute["alert('hi');"] –  Arnoud Buzing Jan 9 at 20:17
    
The link above seems to be broken. Is there an update? –  GregH Aug 20 at 1:10
1  
@GregH, I put a new version with a new link in the post above (not sure how this disappeared). Also, in this new version I renamed the function Execute to JavascriptExecute (more precise function name). –  Arnoud Buzing Aug 20 at 15:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.