惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
Jina AI
Jina AI
Last Week in AI
Last Week in AI
The Cloudflare Blog
博客园 - 【当耐特】
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
博客园_首页
I
InfoQ
G
Google Developers Blog
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
H
Help Net Security
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog

博客园 - 队长

DataSet 序列化时保持行状态 Netcore logging config Some good articles Microservices with Spring Boot ngrok的简单使用 - 队长 通过Ajax上传文件至WebApi服务器 Simple Pipelined Function Simple layout WebApi中利用Razor模板引擎来生成html Spring Boot - Filter实现简单的Http Basic认证 EF DI & MVC EF UoC ks 图片 UEditor Alvin temp Assembly binding Tech Links
利用selenium将edge浏览器里面的网页保存为pdf
队长 · 2021-06-13 · via 博客园 - 队长
from msedge.selenium_tools import Edge, EdgeOptions
import json

# Launch Microsoft Edge (Chromium)
options = EdgeOptions()
options.use_chromium = True

settings = {
    "recentDestinations": [{
        "id": "Save as PDF",
        "origin": "local",
        "account": ""
    }],
    "selectedDestinationId": "Save as PDF",
    "version": 2,
    "isHeaderFooterEnabled": False,
    "mediaSize": {
        "height_microns": 297000,
        "name": "ISO_A4",
        "width_microns": 210000,
        "custom_display_name": "A4"
    },
    "customMargins": {},
    "marginsType": 2,
    "isCssBackgroundEnabled": True
}
prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(settings),
         'savefile.default_directory': r'D:\Learn\WeasyPrint'}
options.add_experimental_option('prefs', prefs)
options.add_argument('--kiosk-printing')

driver = Edge(options = options)
driver.get("http://www.ruanyifeng.com/blog")
driver.execute_script('document.title="PDF文件名";window.print();')

driver.quit() 

参考资料:
模拟谷歌浏览器打印pdf功能_半城繁華半城傷的博客-CSDN博客
https://stackoverflow.com/questions/56897041/how-to-save-opened-page-as-pdf-in-selenium-python