Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I fired up Debian 64 bit on a virtual machine and I did not download the GUI package.(partly because it took just too much time and partly because i wanted to experience the command line!). Anyway, I am here and then I go into python and do this:

>>> import webbrowser
>>> webbrowser.open('www.google.com')

And Now I am looking at a coloured(text only) page of Google like so:

I can see two text fields here. I wanted to ask the following two questions:

  1. where do I enter the search thread?
  2. How do I exit this so as to go back to the command line?

please help me with this query.

(P.S.: I am loving the command line and really think that the people who created programs on this were the real programmers. They could not run the program they write the thousands of time that we do now for debugging and at the same time created great applications. Hats off to those guys!)

share|improve this question
add comment

5 Answers

up vote 2 down vote accepted

It looks like w3m to me. w3m doesn't automatically go into "Enter Text" mode every time the cursor passes over an input field (an annoying feature in lynx when there are lots of inputs on the screen and you're just trying to move past them!) instead you go to the input you want to enter text into, press Return, then you are prompted to enter the text. For multi-line input, it runs a real editor on a temporary file, so you can have all the power of vi or emacs or whatever, instead of a clumsy built-in editing widget.

The most important key in w3m is ShiftH to get to the Help screen. The second most important is ShiftB to go back.

share|improve this answer
    
you are right! it is the w3m browser! and when I did webbrowser.get().name I got www-browser! Thanks a lot! –  IcyFlame Jun 22 '13 at 5:18
add comment

It looks like you are launching links, a text-based browser. To close it, just hit q.

To enter the search term use Down to move to the entry field (__________), enter what you want to search for and hit Enter.

As a general rule, you can exit most command line programs by typing Ctrl+C.


You can launch a website from the command line without using python, just do

lynx www.google.com

or

links www.google.com

Just a quick note on your PS, what makes you think it is harder to run a program 1000 times from the command line? If anything it is easier. Also, you seem to think the command line is a relic. I spend most of my time working in terminals, and writing scripts that are launched from terminals.

share|improve this answer
    
Thank you very much the <kbd>q</kbd> thing works for me. (the <kbd> ctrl + c </kbd> does not). And also, I am still unable to fill the field. I can move my cursor everywhere else but can't enter text. –  IcyFlame Jun 21 '13 at 13:36
    
@IcyFlame I get to the search field with the 12th press of Down. You are probably getting there but miss it, it is not very clearly highlighted. It should be the next field after you pass the Artwork (First day of summer on tooday's google page). If you have a working mouse, you can also try clicking on it. –  terdon Jun 21 '13 at 13:47
    
no no.. i am on a system that does not have GUI package at all... –  IcyFlame Jun 21 '13 at 15:15
    
@IcyFlame I know, you can still have a working mouse though, check out gpm. Anyway, just try hitting down enough times, look at the search field very carefully, it will not be highlighted but there will be a small flashing _ at the far left side. –  terdon Jun 21 '13 at 15:16
add comment

Well, if you like a command line (ncurses based) browser, you could try lynx. Much more intuitive.

share|improve this answer
    
when i use: apt-get install lynx, then it says that the package has been obsoleted. –  IcyFlame Jun 21 '13 at 13:22
    
Strange, the Ubuntu repositories do have it (I just installed it). Perhaps google a bit? –  Sandeep Y Jun 21 '13 at 13:25
    
@IcyFlame that is strange, I can install it on my Debian with no problem. Anyway, try links as in my answer. –  terdon Jun 21 '13 at 13:27
add comment

The first thing you need to know in order to be able to answer your question yourself (via man pages, this site or Google) is to find out which program Python's webbrowser module is starting, and this can be done without any need to guesswork based on what its looks like.

You can find the default that Python selects for you with the following:

>>> import webbrowser
>>> print webbrowser.get().name

(at the Python prompt you can leave out the print statement, but not in a program)

Based on that you should be able to find documentation on the program that is launched, how to select input fields, and how to quit.

If the webbrowser.get().name comes back with xdg-open, then that commandline utility will launch the systems preferred browser application. You can find out what that is with:

update-alternatives --display www-browser

this might not be applicable to your case, since in my experience xdg-open would try and open a file 'www.google.com' if you hand that string to webbrowser.open().

In general you should explicitly use a URL with that function, e.g.:

>>> webbrowser.open('http://google.com')

If you want to change the default that Python selects to any browser mentioned in the other answers or anything else that you have found and fancy, there are various things you can do. You will of course first have to make sure that the actual program that you want to get started, is installed. After that:

  1. there is a programmatic way to achieve your goal in Python by calling webbrowser.get() with a parameter selecting the selection string of browser of your choice.

  2. you can set the BROWSER environment variable as specified in the documentation

  3. if xdg-open is the program called from Python, you can use the above mentioned update-alternatives to set the default browser:

    update-alternatives --config www-browser
    
share|improve this answer
    
thank you! your answer was very informative! But sorry, I can accept only one answer, and the answer from @Wumpus Q Qumbley, gives me the solution I was looking for! Thanks anyway! –  IcyFlame Jun 22 '13 at 5:19
add comment

I'd also mention the browser elinks. Main website is here. Should be in your repository.

share|improve this answer
add comment

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.