Clickable hyperlinks

Deborah Swanson python at deborahswanson.net
Wed Jan 4 23:52:28 EST 2017


Chris Angelico wrote, on January 04, 2017 3:49 PM
> 
> On Thu, Jan 5, 2017 at 9:58 AM, Deborah Swanson 
> <python at deborahswanson.net> wrote:
> >
> > Thank you, thank you! Finally, at least one person on this list
knows 
> > about something (anything) in the python world that is internet
aware. 
<snip>
> 
> We've been all talking at cross purposes a bit in this 
> thread. Most of us thought you were talking about the *user 
> interface* of a clickable link, but if you're talking about 
> the *mechanics* of HTTP downloads, Python has excellent 
> facilities. I'd recommend checking out the third-party 
> 'requests' module on PyPI.

My original question was in fact whether there was a way to make
clickable hyperlinks in a console. I was persuaded after about 10
replies that the answer was no, and I tried with little success to
change the question to one of directly opening a url in a browser from
Python. (In hindsight, maybe I should have started a new thread.) Turns
out this version of the question does have good answers, but the revised
question got totally drowned out in the scramble to show that clickable
links in a console are a no-go. I'm not surprised that you didn't see
the shift in what I was looking for.

<snip>
> 
> Hehe, yeah. It's a big joke that started because XKCD 
> mentioned the language. But actually, the source code for 
> antigravity.py itself isn't significant; all it does is call 
> on the webbrowser module:
> 
https://docs.python.org/3/library/webbrowser.html

I saw how insignificant antigravity's code is when I downloaded it from
the Package Index, and I copied the current version into another message
of yours that I replied to before this one. The original antigravity may
have used webbrowser, but now it just returns a url and hands it off to
import to open it. Maybe the author didn't know import had that
capability until after antigravity had been in the wild awhile.
Regardless, antigravity does point the way to pythonic web access.

> Yes, I'd gotten as far as figuring out that you don't need a clickable

> link. Code that opens a url in a browser would do the job just fine.
Or 
> the webbrowser.open("http://......./") in a Linux terminal you 
> suggest. (I just have to get my Linux machine up and running again to 
> try it.)
>
> All in all, given that clickable urls in a console is a non-starter, 
> this hits the nail on the head. Many thanks again!

Cool! Glad I could help out a bit. There are a few different things you
can consider:

1) Open up a browser tab and let the user see the result
2) Make the request programmatically and access the text of the page for
further processing
3) Invoke a hidden web browser, browse to a URL, submit form data, etc,
as a means of testing a web server.

All three are possible. Take your pick!

ChrisA

I have a fourth option. I use Firefox with profiles and I could make one
specifically for this task, and have the code open the page in that
profile. This would give it it's own window, history, bookmarks, and
sqlite database, which could be handy if a particular url continues to
be a problem, or I want to track it for some reason. In this project I
usually would want to look at the photos, so a text download wouldn't be
that helpful. But it could be in some other project, and I expect to be
doing quite a bit of web work down the road.



More information about the Python-list mailing list