#!/usr/bin/python3

# python3 get_mrkt_value.py
# return 0

import sys, requests, time
import urllib.request
from datetime import timedelta,datetime
from bs4 import BeautifulSoup

# service unavailable
# url = "https://histock.tw/stock/taiexproportion.aspx"

url = "https://stock.capital.com.tw/z/zm/zmd/zmdb.djhtm?MSCI=0"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
print(soup.prettify())
sys.exit(1)
rows = soup.find_all("table", {"class": "tb-index-list"})[0] \
        .find_all("tr")
for i in range(1, len(rows)):
    rank   = rows[i].find_all('td')[0].text
    ticker = rows[i].find_all('td')[1].text
    name   = rows[i].find_all('td')[2].text
    weight = rows[i].find_all('td')[3].text
    print( \
        rank + " " + \
        ticker + " " + \
        name + " " + \
        weight )

rows = soup.find_all("table", {"class": "tb-index-list"})[1] \
        .find_all("tr")
for i in range(1, len(rows)):
    rank   = rows[i].find_all('td')[0].text
    ticker = rows[i].find_all('td')[1].text
    name   = rows[i].find_all('td')[2].text
    weight = rows[i].find_all('td')[3].text
    print( \
        rank + " " + \
        ticker + " " + \
        name + " " + \
        weight )

sys.exit(0)
