Created
February 8, 2020 08:30
-
-
Save jerryan999/a736cad24377e5033d94168d9f3b9a60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from selenium import webdriver | |
def get_pdf(): | |
url = "http://www.baidu.com/ | |
chrome_options = webdriver.ChromeOptions() | |
settings = { | |
"recentDestinations": [{ | |
"id": "Save as PDF", | |
"origin": "local", | |
"account": "" | |
}], | |
"selectedDestinationId": "Save as PDF", | |
"version": 2, | |
"isHeaderFooterEnabled": False, | |
"isCssBackgroundEnabled": True | |
} | |
prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(settings)} | |
chrome_options.add_experimental_option('prefs', prefs) | |
chrome_options.add_argument('--kiosk-printing') | |
CHROMEDRIVER_PATH = '/usr/local/bin/chromedriver' | |
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=CHROMEDRIVER_PATH) | |
driver.get(url) | |
driver.execute_script('window.print();') | |
driver.quit() | |
if __name__ == '__main__': | |
get_pdf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment