如何通过Python使用Selenium登录到suntrust银行帐户

时间:2019-06-10 18:14:26

标签: python-3.x selenium selenium-webdriver webdriver selenium-chromedriver

目标是登录到suntrust银行帐户并抓取有关支票帐户交易数据的信息。

我尝试使用请求库和selenium库。我目前正在使用selenium来查看代码失败的地方。

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

LOGIN_URL = 'https://login.onlinebanking.suntrust.com/olb/login'
userID = 'username'
password = 'password'

chrome_path= "path_to_chromedriver"
chrome_options=webdriver.ChromeOptions()
driver=webdriver.Chrome(chrome_path)

driver.get(LOGIN_URL)
time.sleep(5)
driver.get_cookies()
driver.find_element_by_id('userId').send_keys(userID)
driver.find_element_by_id('password').send_keys(password)
driver.find_element_by_class_name("suntrust-sign-on").click()

程序应成功登录。但是,我收到一条错误消息,内容为 ReasonCode = 6004

1 个答案:

答案 0 :(得分:1)

我对您的代码做了一些修改,并尝试如下登录:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://login.onlinebanking.suntrust.com/olb/login")

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.suntrust-input-text.ng-pristine.ng-valid.ng-touched#userId"))).send_keys("username")
driver.find_element_by_css_selector("input.suntrust-input-text.ng-untouched.ng-pristine.ng-valid#password").send_keys("password")
driver.find_element_by_css_selector("button.suntrust-sign-on.suntrust-button-text>span").click()

但是仍然无法登录。

现在,在检查 SUNTRUST-网上银行登录登录页面的DOM Tree时,您会在<body>标签中找到以下标签:

  • <script type="text/javascript" src="dist/runtime.7d6aba6a1596ee0b757c.js"></script>
  • <script type="text/javascript" src="dist/polyfills.65913a8531010587b6fe.js"></script>
  • <script type="text/javascript" src="dist/scripts.46e57c2d57ad1b3d210d.js"></script>
  • <script type="text/javascript" src="dist/vendor.43f2240dc35276d98b10.js"></script>
  • <script type="text/javascript" src="dist/main.5d227767baa37ef78819.js"></script>

快照

suntrust

短语 dist 的存在明确表明该网站受 Bot Management 服务提供商Distil Networks保护,并且受 ChromeDriver导航被检测到,随后被阻止


Distil

根据文章There Really Is Something About Distil.it...

  

Distil通过观察站点行为并识别刮板特有的模式来保护站点免受自动内容抓取机器人的攻击。当Distil在一个站点上识别出一个恶意bot时,它将创建一个列入黑名单的行为配置文件,并将其部署到所有客户。像漫游器防火墙一样,Distil会检测模式并做出反应。

进一步

  

"One pattern with **Selenium** was automating the theft of Web content",Distil首席执行官拉米·埃塞伊(Rami Essai)在上周的一次采访中表示。 "Even though they can create new bots, we figured out a way to identify Selenium the a tool they're using, so we're blocking Selenium no matter how many times they iterate on that bot. We're doing that now with Python and a lot of different technologies. Once we see a pattern emerge from one type of bot, then we work to reverse engineer the technology they use and identify it as malicious".


参考

您可以在以下位置找到一些相关的讨论