Created
June 28, 2017 16:53
-
-
Save Wei1234c/349957bfced9a2564fc07f0572f2ee52 to your computer and use it in GitHub Desktop.
練習 - 台泥的資產負債表
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Wei
再請教一下,我要抓取台泥損益表,default為”合併累計季表“,欲切換到“合併年表“時 url不會變
(http://goodinfo.tw/StockInfo/StockFinDetail.asp?RPT_CAT=IS_M_QUAR_ACC&STOCK_ID=1101)
請問該怎麼抓累計年表? Appreciated!