Created
April 9, 2020 10:45
-
-
Save philipperemy/21d0c59378ebeb920d25cd4c167af99e to your computer and use it in GitHub Desktop.
Chromedriver headless download file
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
def new_chrome_browser(headless=True, download_path=os.path.dirname(os.path.abspath(__file__))): | |
"""Helper function that creates a new Selenium browser""" | |
options = webdriver.ChromeOptions() | |
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36' | |
if headless: | |
options.add_argument('headless') | |
options.add_argument('--window-size=1280x1024') | |
options.add_argument('--disable-gpu') | |
# options.add_argument(f'user-agent={user_agent}') | |
if download_path is not None: | |
preferences = { | |
'profile.default_content_settings.popups': 0, | |
'download.default_directory': download_path | |
} | |
options.add_experimental_option('prefs', preferences) | |
browser = webdriver.Chrome(options=options) | |
return browser | |
def main(): | |
driver = new_chrome_browser(headless=False) | |
download_file(driver, 'http://ipv4.download.thinkbroadband.com/5MB.zip', '5MB.zip') | |
print('Downloaded!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment