oinume journal

Scratchpad of what I learned

Logging into dmm.com by Selenium

I use Selenium to log into dmm.com because dmm.com requires JavaScript enabled browser. Here is a sample code. You can see Firefox is launched and automatically logging into dmm.com if you use Firefox instead of PhantomJS.

login_dmm.py

#!/usr/bin/env python
# encoding: utf-8

import os
from selenium import webdriver

driver = webdriver.PhantomJS()
#driver = webdriver.Firefox()
driver.get("https://www.dmm.com/my/-/login/=/path=DRVESVwZTldRDlBRRFdIUwwIGFVfVEs_")
login_id = driver.find_element_by_id("login_id")
login_id.send_keys(os.environ["DMM_LOGIN_ID"])
password = driver.find_element_by_id("password")
password.send_keys(os.environ["DMM_LOGIN_PASSWORD"])
driver.find_element_by_tag_name("form").submit()
print(driver.page_source)

driver.quit()

Run

$ brew install phantomjs
$ pip install selenium
$ DMM_LOGIN_ID=your_id DMM_LOGIN_PASSWORD=your_password python ./login_dmm.py