Clickable html links in Python 3.6 shell?

。_饼干妹妹 提交于 2019-12-23 04:46:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!