Download the file by specifying the download destination with Python & Selemiun & Chrome (Windows version)

Source code

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

important point

When specifying the download destination folder, the backslash () is regarded as an escape character, so it must be described as "\".

Recommended Posts

Download the file by specifying the download destination with Python & Selemiun & Chrome (Windows version)
Install by specifying the version with pip
Specifying the module loading destination with GAE python
Download the file in Python
Download csv file with python
Extract the xz file with python
Implemented file download with Python + Bottle
Download the file deployed with appcfg.py
[Python Windows] pip install with Python version
Get the link destination URL by specifying a text sentence with Python scraping (Beautiful Soup) + XPath
Read CSV file with python (Download & parse CSV file)
Check the existence of the file with python
Let's read the RINEX file with Python ①
Read the file line by line in Python
Download files on the web with Python
Read the file line by line in Python
Read the file by specifying the character code.
Download the file with PHP [Under construction]
Overwrite download file for python selenium Chrome
Upload & download wav file to X server (X-Server) by FTP with Python
A memo organized by renaming the file names in the folder with python
[Implementation example] Read the file line by line with Cython (Python) from the last line
Develop Windows apps with Python 3 + Tkinter (exe file)
Download the csv file created by Google Colaboratory
Convert the character code of the file with Python3
Read line by line from a file with Python
I tried searching for files under the folder with Python by file name
Open page in secret mode by specifying browser language with Selenium Python Bindings (Chrome)
Find the cumulative distribution function by sorting (Python version)
Download the file while viewing the progress in Python 3.x
I tried to touch the CSV file with Python
Python3 datetime is faster just by specifying the timezone
[Python] How to specify the download location with youtube-dl
Read the xml file by referring to the Python tutorial
JPEG image generation by specifying quality with Python + OpenCV
[Python] Delete by specifying a tag with Beautiful Soup
Python starting with Windows 7
Check version with python
How to calculate space background X-ray radiation (CXB) with python by specifying the flux range
I replaced the Windows PowerShell cookbook with a python script.
Call the code generated by Cython from C / C ++ (Windows version)
2020/02 Python 3.7 + TensorFlow 2.1 + Keras 2.3.1 + YOLOv3 Object detection with the latest version
[Python] Open the csv file in the folder specified by pandas
Why can I use the module by importing with python?
How to switch the configuration file to be read by Python
[Python] Read the csv file and display the figure with matplotlib
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
[Python3] Call by dynamically specifying the keyword argument of the function
Debug by attaching to the Python process of the SSH destination
The story that Python stopped working with VS Code (Windows 10)
I tried to divide the file into folders with Python
Try to decipher the garbled attachment file name with Python
Python with VS Code (Windows 10)
Run python with PyCharm (Windows)
Draw netCDF file with python
Call the API with python3.
Specify python version with virtualenv
Time synchronization (Windows) with Python
[September 2020 version] Explains the procedure to use Gmail API with Python
Japanese file enumeration with Python2 system on Windows (5C problem countermeasure)