Skip to content

Instantly share code, notes, and snippets.

@Wei1234c
Created June 28, 2017 16:53
Show Gist options
  • Save Wei1234c/349957bfced9a2564fc07f0572f2ee52 to your computer and use it in GitHub Desktop.
Save Wei1234c/349957bfced9a2564fc07f0572f2ee52 to your computer and use it in GitHub Desktop.
練習 - 台泥的資產負債表
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import requests
def get_fs_html(stock_no):
url = 'http://goodinfo.tw/StockInfo/StockFinDetail.asp?RPT_CAT=BS_M_QUAR&STOCK_ID=' + stock_no
html = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'})
return html
def get_table(html):
targetTableIndex = 0
table = pd.read_html(html.content,
attrs = {'class': 'solid_1_padding_3_4_tbl',},
header = 0
)[targetTableIndex]
return table
table = get_table(get_fs_html('1101'))
table.tail(2)
@Wei1234c
Copy link
Author

Wei1234c commented Jul 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment