Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active May 30, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pn11/d6a77e60d6412edcfa7320600c0b784b to your computer and use it in GitHub Desktop.
Save pn11/d6a77e60d6412edcfa7320600c0b784b to your computer and use it in GitHub Desktop.
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