views:

863

answers:

4

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?

A: 

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

Andrew Hare
+3  A: 

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.

Wouter van Nifterick
I am interested. Can you see specific parameters to each site, such as the parameters in the reply by Samir Talwar?
Masi
+1 for the idea to use Links.
Masi
+1  A: 

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.

Samir Talwar
How were you able to see the parameters? When I do a search, I get only "http://www.ocwconsortium.org/#key_word"
Masi
The URL in the location bar changed to that, but then the page was redirected to the URL above. I'm not sure what's different between my browser configuration and yours - I'm using Firefox, and I have JavaScript turned on.
Samir Talwar
+3  A: 
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.

Chas. Owens
Very cool! How did you know the parameters such as "com_coursefinder" and "166" in Itemid?
Masi
+1 for the fantastic snippet.
Masi
I search for mathematics in the search bar and then copied the URL, what browser are you using?
Chas. Owens
On Firefox, the full URL with the parameters shows up in the address bar. Not sure if YMMV on another browser.
David Zaslavsky