Clickable hyperlinks

Chris Angelico rosuav at gmail.com
Wed Jan 4 18:49:15 EST 2017


On Thu, Jan 5, 2017 at 9:58 AM, Deborah Swanson
<python at deborahswanson.net> wrote:
> Chris Angelico wrote, on January 04, 2017 4:16 AM
>> This uses the 'webbrowser' module, which knows about a number
>> of different ways to open a browser, and will attempt them
>> all. So if you can figure out the UI part of things, actually
>> making the link pop up in a browser isn't too hard; for
>> instance, if you're doing OAuth at the command line and need
>> the user to go and authenticate, you can simply
>> webbrowser.open("http://......./") and it'll DTRT.
>>
>
> Thank you, thank you! Finally, at least one person on this list knows
> about something (anything) in the python world that is internet aware.
> It's also occurred to me that Beautifulsoup downloads data from a url,
> so that code must have access to some kind of an internet engine too.

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.

> I googled antigravity and found a number of interesting links.
>
> The History of Python: import antigravity
> http://python-history.blogspot.com/2010/06/import-antigravity.html
>
> Among other things, it was added to Python 3 in 2010, so it's been
> around a little while. And a comment mentions that "The antigravity
> module is also included in Python 2.7."
>
> And a reddit poster tells us that "if you type 'import antigravity' into
> a Python command line your default browser opens the XKCD comic 'Python'
> in a tab."
> https://www.reddit.com/r/ProgrammerHumor/comments/1hvb5n/til_if_you_type
> _import_antigravity_into_a_python/
>
> An "import antigravity" video at
> https://www.youtube.com/watch?v=_V0V6Rk6Fp4

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

> Yes, I'd gotten as far as figuring out that you don't need a clickable
> link. Code that opens a url in a browse 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



More information about the Python-list mailing list