# -*- coding: utf-8 -*-
"""
Created on Sun Dec 9 13:05:58 2018
@author: ryoliu
"""
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'https://goodinfo.tw/StockInfo/StockBzPerformance.asp?STOCK_ID=1402'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/65.0.3325.181 Safari/537.36'}
r = requests.get(url, headers = headers)
r.encoding = 'utf-8'
soup = BeautifulSoup(r.text, 'html.parser')
rows = soup.find('div', {"id": "divFinDetail"}).find('table', {"class": "solid_1_padding_4_0_tbl"})
dfs = pd.read_html(str(rows))
dfs2=dfs[0].loc[2:19]
dfs2.columns = ['年度','股本(億)','財報評分','收盤股價','平均股價','股價漲跌','股價漲跌(%)',\
'營業收入','營業毛利','營業利益','業外損益','稅後淨利','營業毛利(%)','營業利益(%)',\
'業外損益(%)','稅後淨利(%)','ROE(%)','ROA(%)','稅後EPS','成長(元)','BPS(元)']
print (dfs2)
dfs2.to_html("1402.html",index=False)
執行結果如下:
沒有留言:
張貼留言