如何使用Python显示网页?
我想读取 Python 中的用户输入以获取网址(例如 http://www.google.com)然后以 HTML 格式(仅限文本)将网页打印到终端。我尝试使用 pexpect.spawn('elinks')
但 elinks 似乎没有写入标准输出。我还查看了 HTMLParser 模块,但我不知道如何将生成的文本格式化为类似于网页的内容。有什么建议吗?
I want to read user input in Python to get a url (e.g. http://www.google.com) and then print the web page in HTML formatting (text only) to the terminal. I tried using pexpect.spawn('elinks')
but elinks doesn't seem to write to stdout. I also looked at the HTMLParser module, but I don't know how I format the resulting text into something resembling a webpage. Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个不小的挑战。事实上,您想要生成
elinks
,这让我想知道为什么您不直接使用它。查看它具有哪些可扩展性/插件/附加选项,或者尝试重写它以满足您的特定需求。最终,您需要使用curses后端编写自己的浏览器布局引擎。如果您使用Python,
urwid
是curses布局的流行选择。This is no small challenge. The fact that you want to spawn
elinks
makes me wonder why you don't just use it instead. See what extensibility/plugin/addon options it has, or try rewriting it to suit your specific needs.Ultimately, you'll need to write your own browser layout engine with a curses backend. If you're using python,
urwid
is a popular choice for curses layouts.使用 python urllib
输入 url --> urllib -->;该页面-->在控制台中打印
类似于unix中的“curl”
with python urllib
enter the url --> urllib --> the page --> print in console
its similar to "curl" in unix