问题
Say, I have a list full of html links that looks something like this:
https://www.nytimes.com/2017/05/19/realestate/they-can-afford-to-buy-but-they-would-rather-rent.html
When I run a script in Python 3.6 Idle, I get the list as an output in Python 3.6 shell; however, they are not clickable. Is there a simple way to make them clickable in the shell?
I've googled around but I can't seem to find anything involving the Python shell.
Thank you.
回答1:
Since you mentioned py3.6, I'm using f-strings:
text = "This is a link"
target = "http://example.com"
print(f"\u001b]8;;{target}\u001b\\{text}\u001b]8;;\u001b\\")
This will make a clickable link in some shells. (iTerm2, Gnome Terminal and even iPython running in one of these shells.)
To learn more about hyperlink escape sequences, see this Gist or this blog post https://purpleidea.com/blog/2018/06/29/hyperlinks-in-gnome-terminal/
来源:https://stackoverflow.com/questions/44078888/clickable-html-links-in-python-3-6-shell