使用 python 发送要在打印机上打印的 URL
有没有办法用 python 迭代并打印多个 url?我所说的打印并不是指 print() ,而是发送到打印机进行打印。我有以下内容,但本质上想右键单击>打印每一页。这可能吗?
提前致谢。
在 Windows 上(如果相关的话)。
nums = [2015, 2017, 2019, 2021]
url_link = 'www.website.com/{}'
for x in nums:
url = url_link.format(x)
Is there a way to iterate through and print multiple urls with python? And by print i don't mean print() but send to a printer to be printed. I have the following, but want to essentially right click > print each of the pages. Is this possible?
Thanks in advance.
On Windows if thats relevant.
nums = [2015, 2017, 2019, 2021]
url_link = 'www.website.com/{}'
for x in nums:
url = url_link.format(x)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,没有在所有平台上使用 Python 进行打印的标准方法。因此,您需要编写自己的包装函数来打印。
您需要检测您的程序运行的操作系统,然后:
对于 Linux -
对于 Windows:http://timgolden.me.uk/python/win32_how_do_i/print.html
更多资源:
使用python的win32print模块打印PDF文档?
Python:我在什么操作系统上运行?
Unfortunately, there is no standard way to print using Python on all platforms. So you'll need to write your own wrapper function to print.
You need to detect the OS your program is running on, then:
For Linux -
For Windows: http://timgolden.me.uk/python/win32_how_do_i/print.html
More resources:
Print PDF document with python's win32print module?
Python: What OS am I running on?
不可能说您不应该这样做
因此,使用RAW Windows
唯一的全面工作基本解决方案(没有第三方工具)是调用打印机的选择为默认打印机,可以使用基本的shell(或cmd)脚本来完成该打印机,然后用边缘打开URL,然后脚本脚本打印触发器(CTRL+P),如图像的底部所示。
您可以使用Python模拟这些步骤,但是如果从CMD线完成或使用基于URL2PRN的库,则可能会基于安装非商业或许可的Ghostscript。
It is not possible to say you should not be able to, since there are means, however consider
Thus using raw Windows
The only all-round working basic solution (without 3rd party tools) is to invoke selection of the printer as default printer, which can be done using Basic Shell (or cmd) scripting, then open the URL with Edge, then script the print trigger (Ctrl+P) as shown bottom right of image.
You can use Python to emulate those steps but easier if done from the cmd line or using a library that does url2prn based perhaps on installing non commercial or licensed Ghostscript.