Skip to content

Commit

Permalink
Update scraper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kooben209 authored and Kooben209 committed Jan 21, 2019
1 parent adf1faf commit d7ad0fc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scraper.py
Expand Up @@ -25,6 +25,7 @@
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--disable-extensions")

driverException = False
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path='/usr/local/bin/chromedriver')
#driver = webdriver.Chrome(chrome_options=chrome_options)

Expand Down Expand Up @@ -60,12 +61,17 @@ def saveToStore(data):
if os.environ.get('MORPH_DEBUG') == "1":
print(checkURL)
try:
if driverException == True:
driver = webdriver.Chrome(chrome_options=chrome_options)
driverException = False
driver.get(checkURL)
numOfPages = int(driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/div[3]/div/div/div/div[2]/span[3]').text)
except ValueError:
numOfPages = 0
except WebDriverException as e:
print("WebDriverException Exception: {0} Message: {1}".format("e message", str(e)))
driverException = True
driver.quit()
continue

print("NumberOfPages:"+str(numOfPages))
Expand Down Expand Up @@ -154,7 +160,8 @@ def saveToStore(data):

except WebDriverException as e:
print("WebDriverException Exception: {0} Message: {1}".format("e message", str(e)))
finally:
driverException = True
driver.quit()
break
page +=1
time.sleep(sleepTime)
Expand All @@ -176,4 +183,4 @@ def saveToStore(data):
if os.environ.get('MORPH_RUN_SOLD_PRICES') == "1":
getAllSoldPrices(currentMonth)

sys.exit(0)
sys.exit(0)

0 comments on commit d7ad0fc

Please sign in to comment.