Last active
August 17, 2017 14:52
-
-
Save MartinThoma/8b55b296375f83cbe4b70179930e70bd to your computer and use it in GitHub Desktop.
This file contains 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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.common.by import By | |
def get_browser(): | |
path_to_chromedriver = '/usr/lib/chromium-browser/chromedriver' | |
chrome_options = webdriver.ChromeOptions() | |
prefs = {"plugins.plugins_disabled": ["Chrome PDF Viewer"]} | |
chrome_options.add_experimental_option("prefs", prefs) | |
browser = webdriver.Chrome(executable_path=path_to_chromedriver, | |
chrome_options=chrome_options) | |
return browser | |
def download_file_example(browser): | |
browser.get("https://martin-thoma.com/author/martin-thoma/") | |
links = browser.find_elements_by_xpath('//a') | |
for link in links: | |
if link.get_attribute('href').endswith('.pdf'): | |
print(link.get_attribute("outerHTML")) | |
link.click() | |
break | |
browser = get_browser() | |
download_file_example(browser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment