How can I execute javascript in Bash?

I try to get to a page straight from Bash at http://www.ocwconsortium.org/. The page appears when you write mathematics to the field at the top right corner. I tested

open http://www.ocwconsortium.org/#mathematics

but it leads to the main page. It is clearly some javascript thing. How can I get the results straight from Bash on the first page?

[Clarification]

Let's take an example. I have the following lines for a Math search engine in .bashrc:

alias mathundergradsearch='/Users/user/bin/mathundergraduate'

Things in a separate file:

#!/bin/sh                                                                                                                                                                     

q=$1
w=$2
e=$3
r=$4
t=$5

open "http://www.google.com/cse?cx=007883453237583604479%3A1qd7hky6khe&ie=UTF-8&q=$q+$w+$e+$r+$t&hl=en"

Now, I want something similar to the example. The difference is that the other site contains javascript or something that does not allow me to see the parameters. How could I know where to put the search parameters as I cannot see the details?

Upvotes: 3

Views: 7228

Answers (5)

Detro
Detro

Reputation: 341

Check this out: http://www.phantomjs.org/.

PhantomJS it's a CLI tool that runs a real, fully-fledged Browser without the Chrome.

Upvotes: 0

Chas. Owens
Chas. Owens

Reputation: 64909

open "http://www.ocwconsortium.org/index.php?q=mathematics&option=com_coursefinder&uss=1&l=&s=&Itemid=166&b.x=0&b.y=0&b=search"

You need quotes because the URL contains characters the shell considers to be special.

Upvotes: 3

Samir Talwar
Samir Talwar

Reputation: 14330

I didn't get anything handled by JavaScript - it just took me to

http://www.ocwconsortium.org/index.php?q=mathematics&option=com_coursefinder&uss=1&l=&s=&Itemid=166&b.x=0&b.y=0&b=search

Replacing mathematics (right after q=) should work. You may be able to strip out some of that query string, but I tried a couple of things and and it didn't play nice.

Don't forget to encode your query for URLs.

Upvotes: 1

Wouter van Nifterick
Wouter van Nifterick

Reputation: 24086

The Links web browser more or less runs from the commandline (like lynx) and supports basic javascript.

Even though the title of the post sounds general, your question is very specific. It's unclear to me what you're trying to achieve in the end. Clearly you can access sites that rely heavily on javascript (else you wouldn't be able to post your question here), so I'm sure that you can open the mentioned site in a normal browser.

If you just want to execute javascript from the commandline (as the title suggests), it's easy if you're running bash via cygwin. You just call cscript.exe and provide a .js scriptname of what you wish to execute.

Upvotes: 3

Andrew Hare
Andrew Hare

Reputation: 351466

You will need to parse the response, find the URL that is being opened via JavaScript and then open that URL.

Upvotes: 0

Related Questions