python-3.x - 如何通过 Python 使用 Selenium 登录 suntrust 银行账户
问题描述
目标是登录到一个 suntrust 银行账户并获取有关支票账户交易数据的信息。
我尝试过使用 request library 和 selenium library 。我目前正在使用 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。
解决方案
我对您的代码进行了一些修改,并尝试按如下方式登录:
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 - Online Banking Sign On登录页面的DOM 树时,您会在标签中找到以下标签:<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>
快照
短语dist的存在清楚地表明该网站受到Bot Management服务提供商Distil Networks的保护,并且ChromeDriver的导航被检测到并随后被阻止。
蒸馏
Distil 通过观察网站行为和识别抓取工具特有的模式来保护网站免受自动内容抓取机器人的侵害。当 Distil 在一个站点上识别出恶意机器人时,它会创建一个列入黑名单的行为配置文件,并部署到其所有客户。类似于机器人防火墙的东西,Distil 检测模式并做出反应。
更远,
"One pattern with **Selenium** was automating the theft of Web content"
,Distil 首席执行官 Rami Essaid 在上周接受采访时表示。"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".
参考
您可以在以下位置找到一些相关的讨论:
推荐阅读
- apache-spark - 替换 Pyspark Dataframe 中列中的空值
- symfony - 无法显示选择字段类型元素。如何正确地将自定义实体表示添加到 Sulu 表单?
- python - 从具有多行的熊猫数据框中更新 BigQuery 表的最佳方法是什么
- apache-kafka - JDBC Sink 连接器 - 使用 kafka-connect 从多个主题更新插入多个表 - 跟进
- c++ - 循环执行的区别
- c# - 在 DataGridView 中使文本重叠
- php - 如何在背包-laravel 的注册表单中添加更多字段?
- css - Bootstrap 3 - 在 MD 上移动一列
- c# - WebClient 底层连接关闭/启用 SSL/TLS,但仅在本地机器上工作
- android - sudo su -c ls 输出末尾的额外“:”,仅在使用通配符时