Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 511
Léo Léopold Hertz 준영 Avatar asked May 08 '26 02:05

Léo Léopold Hertz 준영


2 Answers

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.

like image 104
Chas. Owens Avatar answered May 10 '26 16:05

Chas. Owens


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.

like image 36
Wouter van Nifterick Avatar answered May 10 '26 17:05

Wouter van Nifterick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!