111 lines
4.4 KiB
Python
111 lines
4.4 KiB
Python
import traceback
|
|
import time
|
|
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support import expected_conditions as ec
|
|
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
from Basic.log_manager import get_logging
|
|
|
|
|
|
def smart_credit_refresh_status(email, password):
|
|
logger = get_logging()
|
|
try:
|
|
url = "https://www.smartcredit.com/"
|
|
|
|
chrome_path = "/usr/lib/chromium-browser/chromedriver"
|
|
#chrome_local_path = "D:\\scrapper\\chromedriver_win32\\chromedriver.exe"
|
|
chrome_local_path = "D:\\scrapper\\chromedriver_win64\\chromedriver.exe"
|
|
|
|
option = webdriver.ChromeOptions()
|
|
option.add_argument('--headless')
|
|
option.add_argument('--no-sandbox')
|
|
option.add_argument('--disable-dev-sh-usage')
|
|
#driver = webdriver.Chrome(chrome_path,options=option)
|
|
#driver = webdriver.Chrome(chrome_local_path,options=option)
|
|
|
|
phantomjs_server_path = "/usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs"
|
|
phantomjs_local_path = "D:\\scrapper\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe"
|
|
|
|
driver = webdriver.PhantomJS(executable_path= phantomjs_server_path,service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
|
|
#driver = webdriver.PhantomJS(executable_path= phantomjs_local_path,service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
|
|
|
|
|
|
driver.get(url + 'login/')
|
|
driver.find_element_by_name('j_username').send_keys(email)
|
|
driver.find_element_by_name('j_password').send_keys(password)
|
|
driver.find_element_by_xpath('//*[@id="login-form"]/div[1]/div/button').click()
|
|
|
|
timeout = 10
|
|
time.sleep(5)
|
|
try:
|
|
alert_div = driver.find_element_by_class_name("alert-danger")
|
|
paragraph_element = alert_div.find_element_by_tag_name("p")
|
|
driver.quit()
|
|
return "INVALID_LOGIN"
|
|
|
|
except:
|
|
pass
|
|
|
|
try:
|
|
WebDriverWait(driver, timeout).until(ec.url_to_be(url + 'member/home/'))
|
|
|
|
if driver.current_url == url + 'member/home/':
|
|
driver.get(url + 'member/credit-report/3b/')
|
|
|
|
btn_text = None
|
|
try:
|
|
element_present = ec.presence_of_element_located(
|
|
(By.CSS_SELECTOR, '.alert.alert-warning.fade.in.text-center.mb-2')
|
|
)
|
|
WebDriverWait(driver, timeout).until(element_present)
|
|
btn_text = driver.find_element(
|
|
By.CSS_SELECTOR, '.alert.alert-warning.fade.in.text-center.mb-2'
|
|
).text
|
|
except TimeoutException:
|
|
pass
|
|
|
|
driver.get(url + 'member/credit-report/3b/confirm.htm')
|
|
driver.maximize_window()
|
|
response = {
|
|
'button_type': 0,
|
|
'refresh_date': btn_text
|
|
}
|
|
|
|
try:
|
|
driver.find_element(By.ID, "toggle-marketing")
|
|
btn_text = driver.find_element(By.ID, "toggle-marketing").text
|
|
|
|
if btn_text and str(btn_text).lower().strip() == 'order your 3-bureau report & scores':
|
|
response['button_type'] = 1
|
|
response['refresh_date'] = btn_text
|
|
except NoSuchElementException:
|
|
pass
|
|
|
|
try:
|
|
driver.find_element(By.NAME, "isConfirmedTerms")
|
|
btn_text = driver.find_element(By.XPATH, '//*[@id="confirm-3b-form"]/div[4]/div/div/button').text
|
|
|
|
if btn_text and str(btn_text).lower().strip() == 'place order now':
|
|
response['button_type'] = 2
|
|
response['refresh_date'] = btn_text
|
|
except NoSuchElementException:
|
|
pass
|
|
|
|
driver.quit()
|
|
return response
|
|
|
|
driver.quit()
|
|
return "ERROR"
|
|
|
|
except TimeoutException:
|
|
logger.error("email: "+email+ " "+traceback.format_exc())
|
|
driver.quit()
|
|
return "TIME_OUT"
|
|
|
|
except Exception:
|
|
logger.error("email: "+email+ " "+traceback.format_exc())
|
|
traceback.print_exc()
|
|
#return traceback.format_exc()
|
|
return "ERROR"
|