Skip to content

Commit

Permalink
chromedriver update, auto version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoongi Kim committed Aug 12, 2019
1 parent 422d8f3 commit 392a8b4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
Binary file modified chromedriver/chromedriver_linux
Binary file not shown.
Binary file modified chromedriver/chromedriver_mac
Binary file not shown.
File renamed without changes.
Binary file modified chromedriver/chromedriver_win.exe
Binary file not shown.
28 changes: 27 additions & 1 deletion collect_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import platform
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os.path as osp


class CollectLinks:
Expand All @@ -39,10 +40,35 @@ def __init__(self):
print('Detected OS : Mac')
executable = './chromedriver/chromedriver_mac'
else:
assert False, 'Unknown OS Type'
raise OSError('Unknown OS Type')

if not osp.exists(executable):
raise FileNotFoundError('Chromedriver file should be placed at {}'.format(executable))

self.browser = webdriver.Chrome(executable)

browser_version = 'Failed to detect version'
chromedriver_version = 'Failed to detect version'
major_version_different = False

if 'browserVersion' in self.browser.capabilities:
browser_version = str(self.browser.capabilities['browserVersion'])

if 'chrome' in self.browser.capabilities:
if 'chromedriverVersion' in self.browser.capabilities['chrome']:
chromedriver_version = str(self.browser.capabilities['chrome']['chromedriverVersion']).split(' ')[0]

if browser_version.split('.')[0] != chromedriver_version.split('.')[0]:
major_version_different = True

print('_________________________________')
print('Current web-browser version:\t{}'.format(browser_version))
print('Current chrome-driver version:\t{}'.format(chromedriver_version))
if major_version_different:
print('warning: Version different')
print('Download correct version at "http://chromedriver.chromium.org/downloads" and place in "./chromedriver"')
print('_________________________________')

def get_scroll(self):
pos = self.browser.execute_script("return window.pageYOffset;")
return pos
Expand Down
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ def download_images(self, keyword, links, site_name):
def download_from_site(self, keyword, site_code):
site_name = Sites.get_text(site_code)
add_url = Sites.get_face_url(site_code) if self.face else ""
collect = CollectLinks() # initialize chrome driver

try:
collect = CollectLinks() # initialize chrome driver
except Exception as e:
print('Error occurred while initializing chromedriver - {}'.format(e))
return

try:
print('Collecting links... {} from {}'.format(keyword, site_name))
Expand Down

0 comments on commit 392a8b4

Please sign in to comment.