Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active August 17, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinThoma/8b55b296375f83cbe4b70179930e70bd to your computer and use it in GitHub Desktop.
Save MartinThoma/8b55b296375f83cbe4b70179930e70bd to your computer and use it in GitHub Desktop.
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