from urllib import request
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import pandas as pd
import os

def get_pages(url):
	res = request.urlopen(url)
	soup = BeautifulSoup(res,"html.parser")
	res.close()
	return soup

def get_tables(url):
	data = pd.read_html(url)
	return data

def get_driver(opt=None):
	dp = r"C:\driver\94\chromedriver.exe"
	options = Options()
	if opt:
		options.add_argument('--headless')
	return webdriver.Chrome(dp, options=options)

def set_login(d):
	d.get(r"https://regist.netkeiba.com/account/?pid=login")
	# d.switch_to_window(d.window_handles[1])
	loginid = d.find_element_by_name("login_id")
	pswd = d.find_element_by_name('pswd')
	logbtn = d.find_element_by_class_name('loginBtn__wrap').find_element_by_tag_name('input')
	loginid.send_keys(os.environ['email'])
	pswd.send_keys(os.environ['passwd'])
	logbtn.click()
	return d
