Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active May 30, 2018
Embed
What would you like to do?
rakutenedy_csv.py
# -*- coding: utf-8 -*-
import sys
import time
USERNAME = 'xxxxxxxx@xxxxxxxx'
PASSWORD = 'xxxxxxxx'
DATESTR = '201507'
def get_html(datestr = DATESTR):
from splinter import Browser
br = Browser('chrome')
br.visit('https://edy.rakuten.co.jp/my/login/ehis')
br.fill('u', USERNAME)
br.fill('p', PASSWORD)
br.find_by_name('submit').click()
time.sleep(1)
click_button = br.find_by_id(datestr)
if len(click_button) == 0:
print('指定された月のデータが存在しません。')
br.quit()
sys.exit()
click_button.click()
time.sleep(1)
h = br.html
br.quit()
return h
def trans_to_csv(html):
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
d = eval(soup.find(id="his_record")['value'])
s = ""
for row in d:
l = []
l.append(row["tri_date"].replace('\\/','/'))
l.append(row["shop_name"] if row["shop_name"] else row["log_type"])
l.append(row["tri_amt"].replace(',',''))
s += (",".join(l)) + "\n"
return s
if __name__ == "__main__":
month = sys.argv[1]
html = get_html(month)
csv = trans_to_csv(html)
file = open("edy_{}.csv".format(month), "w")
file.write(csv)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment