Author Topic: Tarik Mutasi BNI dengan Python  (Read 2396 times)

fahrizal.maruf

  • Jr. Member
  • **
  • Posts: 133
  • Berusaha untuk selalu bersyukur
Tarik Mutasi BNI dengan Python
« on: April 01, 2016, 10:54:57 PM »
Code: [Select]
#! /usr/bin/python
refresh_second = 30
username = "username_bni"
password = "password_bni"
bank_url = "https://ibank.bni.co.id/MBAWeb/FMB"
no_rekening = "00000000123456789" #bisa di lihat di inetbanking bni
import sys
import time
import requests
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
from selenium.common.exceptions import NoSuchElementException
def log(text):
print time.strftime("[%d/%m/%Y"),time.strftime("%H:%M:%S]"),text

while True:
error=False
secondtosleep = refresh_second
log("Initializing PhantomJS driver")
try:
browser=webdriver.PhantomJS()
except:
log("Can't use PhantomJS as driver")
else:
log("Opening url: "+bank_url)
browser.get(bank_url)
log("Web Title is: "+browser.title)
#LOGIN PROCESS
try:
btnMasuk = browser.find_element_by_css_selector('a#RetailUser')
except NoSuchElementException:
error=True
log("Error opening login page")
#print browser.page_source.encode('utf-8').strip()
else:
btnMasuk.click()
try:
elUsername = browser.find_element_by_css_selector('input#CorpId')
elPassword = browser.find_element_by_css_selector('input#PassWord')
elLoginBtn = browser.find_element_by_css_selector('input[type=submit]')
except NoSuchElementException:
error=True
log("error processing login")
#print browser.page_source.encode('utf-8').strip()
else:
elUsername.send_keys(username)
elPassword.send_keys(password)
elLoginBtn.click()
try:
elMenuRekening = browser.find_element_by_link_text('REKENING')
except NoSuchElementException:
error=True
log("Error opening menu REKENING")
#print browser.page_source.encode('utf-8').strip()
else:
elMenuRekening.click()
try:
elMenuTrxTerakhir = browser.find_element_by_link_text('TRANSAKSI TERAKHIR')
except NoSuchElementException:
error=True
log("Error opening menu TRANSAKSI TERAKHIR")
#print browser.page_source.encode('utf-8').strip()
else:
elMenuTrxTerakhir.click()
try:
browser.find_element_by_xpath("//select[@name='MiniStmt']/option[text()='"+no_rekening+"']").click()
browser.find_element_by_css_selector('input#Go[type=submit]').click()
except NoSuchElementException:
error=True
log("error getting transaksi terakhir")
#print browser.page_source.encode('utf-8').strip()
else:
try:
elForm = browser.find_element_by_css_selector('form#form')
except NoSuchElementException:
error=True
log("Error parsing transaksi terakhir")
else:
log("Parsing transactions")
trx=[]
#Get tgl transaksi
row=0
els = elForm.find_elements_by_css_selector('td#s1 > span#H')
for el in els:
val=el.text
if val:
#print "Trx Tgl:",val
trx.append({'tgl':val,'uraian':None,'tipe':None,'nominal':0,'saldo':0})
row+=1
#get uraian transaksi
row=0
els = elForm.find_elements_by_css_selector('td#s2 > span#H')
for el in els:
val=el.text
if val:
#print val
trx[row]['uraian']=val.upper()
row+=1
#get tipe transaksi
row=0
els = elForm.find_elements_by_css_selector('td#s3 > span#H')
for el in els:
val=el.text.upper()
if val:
if val=='DB' or val=='CR':
#print val
trx[row]['tipe']=val
row+=1
#get nominal transaksi
row=0
els = elForm.find_elements_by_css_selector('td#s4 > span#H')
for el in els:
val=el.text
if val:
#print val
trx[row]['nominal']=val.replace('.','').split(',')[0]
row+=1
#get saldo
row=0
els = elForm.find_elements_by_css_selector('td#s5 > span#H')
for el in els:
val=el.text
if val:
#print val
trx[row]['saldo']=val.replace('.','').split(',')[0].replace('IDR ','')
row+=1

#PROSES LOGOUT
elLogoutBtn = browser.find_element_by_css_selector('input#LogOut')
elLogoutBtn.click()
elKeluarBtn = browser.find_element_by_css_selector('input#__LOGOUT__')
elKeluarBtn.click()

#Post data to server
for t in trx:
datatrx = t['tgl']+"|"+t['uraian']+"|"+t['nominal']+"|"+t['tipe']+"|"+t['saldo']
log(datatrx)

error=False
if error:
secondtosleep=300 #pause 5 menit

ts=time.strftime("[%d/%m/%Y")+" "+time.strftime("%H:%M:%S]")
for i in range(secondtosleep):
cd=secondtosleep-(i+1)
time.sleep(1)
sys.stdout.write("\r"+ts+" Starting in "+str(cd)+" second  ")
sys.stdout.flush()
sys.stdout.write("\r")
sys.stdout.flush()
-

kangibnu

  • Jr. Member
  • **
  • Posts: 178
  • Amalkan ilmu dgn menulis dan mengajarkannya
    • http://zull-pulsa.com
Re: Tarik Mutasi BNI dengan Python
« Reply #1 on: April 26, 2016, 11:45:09 PM »
mantab... run
Versi : Advance (ASELI ) OID : CihSAyWmzQ_rahasia
Alamat: JL Prabu Loro Kel.Bakungan Kec.Glagah Kab.Banyuwangi -JATIM - HP/ WA : 0812525 2497 PIN BB:D363A8CA http://zull-pulsa.com - Inet: XL , Indosat
PPOB Pasca, PDAM - H2H Tsell NAS , XL NAS, ISAT, Konsultasi software pendukung