Re: [問題] 如何抓取上市股票交易明細

看板Python作者 (小諺)時間8年前 (2017/01/06 11:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
感謝各位版友回覆,我參考了chliu版友提供的文章,利用前輩的程式碼進行修改, 下面是純分享。 # -*- coding: utf-8 -*- from urllib import urlencode import httplib2 import pandas as pd url = 'http://www.tse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php' data = { 'download': 'html','query_year': '2017', 'query_month': '01', 'CO_ID': '2330'} agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0' httplib2.debuglevel = 1 conn = httplib2.Http('.cache') headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': agent} resp, content = conn.request(url, 'POST', urlencode(data), headers) df=pd.read_html(content) df1=pd.DataFrame(df[0]) 這樣就可以用Pandas針對特定股票分析資訊了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.67.75.74 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1483674099.A.AAE.html
文章代碼(AID): #1ORn7pgk (Python)
文章代碼(AID): #1ORn7pgk (Python)