test.py
#Import webdriver from selenium
from selenium import webdriver
#Specify the download destination folder
#Example of use:
#download_directory='c:\\Users\\<Your home directory>\\Downloads'
#Note: Backslash(\)Is "\\"Must be written with the escape character
download_directory='<Where you want to save the download file>'
###############################################################
###You can download the file without displaying the dialog.
###File download_It is saved in the path set in directory.
#
#Example of use:
# driver =init_selenium()
# target_url='www.WannaGetFileFromHere.com'
# driver.get(target_url)
###############################################################
def init_selenium():
###Set options for Chrome
chop = webdriver.ChromeOptions() #
prefs = {"download.default_directory" : download_directory}
chop.add_experimental_option("prefs",prefs)
chop.add_argument('--ignore-certificate-errors') #SSL error countermeasures
driver = webdriver.Chrome(chrome_options = chop)
return driver
When specifying the download destination folder, the backslash () is regarded as an escape character, so it must be described as "\".
Recommended Posts