0

I have to automate the "imitation" of a "human" by using a webbrowser that supports javascript.

I need it because there is a javascript link on the website that can be only used if the webbrowser supports javascript, so curl/wget cannot do it.

Question: How can I do this on a Linux terminal? Or is it impossible?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
LoukiosValentine79
  • 1,479
  • 3
  • 21
  • 43
  • Have you tried [selenium](http://docs.seleniumhq.org/)? or [watir](http://watir.com/)? – fredtantini Jun 10 '15 at 10:50
  • [WWW::Mechanize::Firefox](http://p3rl.org/WWW::Mechanize::Firefox), [WWW::Mechanize::PhantomJS](http://p3rl.org/WWW::Mechanize::PhantomJS)... – choroba Jun 10 '15 at 10:52

1 Answers1

3

This can be done using two ways:

  1. GUI way ==> Use Selenium
  2. Terminal way ==> Use ghost.py or phantomjs

Terminal Way

You can go ahead and use ghost.py or phantomjs. Read their documentations on how to use them here : Ghost.py and phantomjs

An example using Ghost.py

First install ghost.py. To install this, you will need pip. Hence, do this on a ubuntu based system:

sudo apt-get install python-pip
sudo pip install Ghost.py

Now, you can use Ghost.py in your script to automate any javascript based actions. Here is a sample script derived from the official documentation:

#!/usr/bin/python
#script.py

from ghost import Ghost 
ghost = Ghost()

page, resources = ghost.open('http://my.web.page')

#Run javascript action
result, resources = ghost.evaluate( "document.getElementById('my-input').getAttribute('value');")
shivams
  • 4,505
  • 3
  • 19
  • 36