ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[­ì³Ð] python¤W¥«Âd¤T¤jªk¤H¶R½æ¶W¤é³ø¸ê®Æ¤U¸ü

[­ì³Ð] python¤W¥«Âd¤T¤jªk¤H¶R½æ¶W¤é³ø¸ê®Æ¤U¸ü

¥i¥Î¨Ó¤U¸ü¤W¥«Âd¤T¤jªk¤H¶R½æ¶W¤é³ø¸ê®Æ¡C»PpyÀɦP¤@¸ô®|¤Uªºpath.ini¥i³]©wcsv¦s©ñ¦ì¸m¡Aª`·N¸ô®|­n¥]¬A³Ì«á¤@­Ó"\"¡A¦p¡GC:\user\desktop\test\¡C
ªþ¤W°õ¦æÀÉ
  1. import requests
  2. import time
  3. import os

  4. mydate = time.strftime("%Y/%m/%d")
  5. year = str(int(mydate[0:4])-1911)
  6. mydate2 = mydate.replace(mydate[0:4],year)

  7. setting = os.getcwd() + "\\" + "path.ini"

  8. if os.path.exists(setting):
  9.     with open(setting, 'r') as r:
  10.         path = r.read()
  11.     if not os.path.exists(path):
  12.         os.makedirs(path)
  13. else:
  14.     path = ""

  15. headers = {"User-Agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"}


  16. url1 = "http://www.twse.com.tw/ch/trading/fund/T86/T86.php"
  17. payload1 = {"download": "csv",
  18.             "qdate": mydate2,
  19.             "select2": "ALLBUT0999",
  20.             "sorting": "by_issue"}

  21. res1 = requests.post(url1, headers=headers, data=payload1, stream=True)

  22. fName1 = path + mydate.replace("/","") + ".csv"

  23. with open(fName1, 'wb') as f1:
  24.     for chunk in res1.iter_content(1024):
  25.         f1.write(chunk)


  26. url3 = "http://www.tpex.org.tw/web/stock/3insti/daily_trade/\
  27. 3itrade_hedge_download.php?l=zh-tw&se=EW&t=D&d=" + mydate2 + "&s=0,asc,0"

  28. res3 = requests.get(url3, headers=headers, stream=True)

  29. fName3 = path + "BIGD_" + mydate2.replace("/","") + ".csv"

  30. with open(fName3, 'wb') as f3:
  31.     for chunk in res3.iter_content(1024):
  32.         f3.write(chunk)


  33. url2 = "http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/MI_INDEX.php"
  34. payload2 = {"download": "csv",
  35.             "qdate": mydate2,
  36.             "selectType": "ALLBUT0999"}

  37. res2 = requests.post(url2, headers=headers, data=payload2,stream=True)

  38. fName2= path + "A11" + mydate.replace("/","") + ".csv"

  39. with open(fName2, 'wb') as f2:
  40.     for chunk in res2.iter_content(1024):
  41.         f2.write(chunk)
  42.         

  43. url4 = "http://www.tpex.org.tw/web/stock/aftertrading/otc_quotes_no1430/\
  44. stk_wn1430_download.php?l=zh-tw&d=" + mydate2 + "&se=EW&s=0,asc,0"

  45. res4 = requests.post(url4, headers=headers, data=payload2,stream=True)

  46. fName4 = path + "SQUOTE_EW_" + mydate2.replace("/","") + ".csv"

  47. with open(fName4, 'wb') as f4:
  48.     for chunk in res4.iter_content(1024):
  49.         f4.write(chunk)
½Æ»s¥N½X

¬O±qÃÒ¥æ©Ò§ì¶Ü??  µý¥æ©Ò³Ìªñ³o¨â¦~«÷©R¾×¡A¤p§Ì±q Excel VBA Âà¨ì python ªF«÷¦è´ê¦n¤£®e©ö§ï¦¨¥\¤F¡Aµ²ªG¦n¨S´X¤ÑÁÙ¬O¤@ª½¾×¡A
²{¦b­nÂà¦V¹d¦ëºô§ì¸ê®Æ¡A¤£ª¾¹D¦³¤j¤jª¾¹D«ç»ò¸ÑªR¹d¦ëºôªº¸ê®Æ¤U¸üºô§}®æ¦¡¶Ü??  ·s¤â¸ÑªR¯uµh­W......

TOP

(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001BBBD77B6D8>: Failed to establish a new connection: [WinError 10061] µLªk³s½u¡A¦]¬°¥Ø¼Ð¹q¸£©Úµ´³s½u¡C',))
--->¥X²{¤F³o¼ËªºError~

TOP

¦b¶×¤Jºô­¶®É¡A±`±`·|¹J¨ìµLªk¶×¤Jªºª¬ªp¡A½Ð°Ý¸Ó¦p¦ó¸Ñ¨M©O?
¬O§_¦³¬ÛÃöªº¤å³¹¥i¨Ñ°Ñ¦Ò?

EX¡Gmini S&P ¿ï¾ÜÅvªº¦U¼i¬ù»ù¥æ©ö¼Æ¾Ú(¦bCMEºô¯¸)
§Ú·Q­n³z¹LVBA¤U¸ü«o¤@ª½¥¢±Ñ...

¦]¬°§ÚµLªkµo¥¬ºô§}(³Q¨t²Î¾×±¼)¡A©Ò¥H¥u¯à¥Î¶K¤W¹Ï¤ù

[attach]27980[/attach]

TOP

¦b¶×¤Jºô­¶®É¡A±`±`·|¹J¨ìµLªk¶×¤Jªºª¬ªp¡A½Ð°Ý¸Ó¦p¦ó¸Ñ¨M©O?
¬O§_¦³¬ÛÃöªº¤å³¹¥i¨Ñ°Ñ¦Ò?

EX¡Gmini S&P ¿ï¾ÜÅvªº¦U¼i¬ù»ù¥æ©ö¼Æ¾Ú(¦bCMEºô¯¸)
§Ú·Q­n³z¹LVBA¤U¸ü«o¤@ª½¥¢±Ñ...

¦]¬°§ÚµLªkµo¥¬ºô§}(³Q¨t²Î¾×±¼)¡A©Ò¥H¥u¯à¥Î¶K¤W¹Ï¤ù

[attach]27980[/attach]

TOP

import pandas as pd
import requests
import html5lib
from bs4 import BeautifulSoup
payload={
'encodeURIComponent':'1',
'step':'1',
'firstin':'1',
'off':'1',
'keyword4':'',
'code1':'',
'TYPEK2':'',
'checkbtn':'',
'queryName':'co_id',
'inpuType':'co_id',
'TYPEK':'all',
'isnew':'false',
'co_id':'1101',
'year':'105',
'month':'11'  
}
res= requests.post('hXXp://mops.twse.com.tw/mops/web/ajax_t05st10_ifrs',data=payload)
res.encoding='utf-8'
soup=BeautifulSoup(res, "lxml")
s=pd.read_html(soup)


½Ð°Ý§Ú¼g³o¼ËpandasŪ¤£¨ìtable
Åã¥Üno table  
¸Ó¦p¦ó­×§ï?

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-10-15 07:52 ½s¿è

¦^´_ 167# zyzzyva
¥Ø«e§Ú¤£«H¨¸¡A¤S±N Anaconda3-4.2.0-Windows-x86_64.exe ¦w¸Ë¨ì C ¼Ñ¡A
¨Ï¥Î¤è¦¡·Ó #166 ©Ò­z°õ¦æ¡A¤j³¡¤Àªº *.ipynb §¡¯à¶¶§Q°õ¦æ¡A
«e°}¤l (¤@¶g«e) ¬O¯à¥¿±`§@·~¡F¸g§A³o»ò¤@´£¥Ü¡A¹îı·¥¦³¥i¯à¬O OS ªº¦Û°Ê½u¤W§ó·s
¦³Ãö¡C´X¦~«e¥çµo¥Í¹L¦¹Ãþ¦ü±¡ªp¡G§Y Excel »P¨é°Óªº DDE ³s½u¡A¦³¤Ñ¦b¸g¹L·L³n§@·~¨t²Î
§ó·s Service Pack «á§Y«Å§iµLªk§ä¨ì³s¤W DDE ªº®M¥ó¡F¸gÆ[¹î¨ºªñ¤é°ÊºA¡A¶È¦³ Service Pack
³Q§ó·s¡A©ó¬O¤â°Ê±N¨ä·í¤é§ó·sªº¤¸¥ó¤@¤@ÁÙ­ì¡A¦b­«·s¶}¾÷«áÀH§Y¥¿±`§@·~¡C
·í®É¥»½×¾Â (»P¨ä¥L½×¾Â) ¥ç¦³¼Æ¦ì¥ý¶i¥ç´¿µo¥Í¡A§Ú±N¸Ñ¨M¤è¦¡§iª¾¤j®a¤@¥­¦wµL¨Æ¡C
¥Ø«e¬O¨Ï¥Î Windows 10 (­ì¥»¬° Window 7¡A¸g·L³n§K¶O½u¤W¦Û°Ê¤É¯Å¦Ü Window 10)¡C

TOP

¦^´_ 166# c_c_lai
§Ú¦³¥Î¥t¤@¥xwin7¹q¸£Äé Anaconda3-4.2.0-Windows-x86_64.exe¡A°õ¦æ°_¨Ó³£¥¿±`¡C
¤£¹L¯à¶¶§Q¸Ñ¨M¯u¬O¤Ó¦n¤F¡A³oºØÀô¹Ò³]©wªº°ÝÃDÅܼƫܦh¡A¦³®É­Ô§ä¤£¥X½T¤Áªº­ì¦]¡A¯uªº¦³ÂI·Ð¤H¡C

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-10-14 11:39 ½s¿è

¦^´_ 163# zyzzyva
±o¨ì¤@­Óµ²½×¡G
µL½×¦w¸Ë¥ô¦óª©¥»¡A³z¹L Anaconda Navigator ¥h°õ¦æ spider ©Î jupyter notebook
µ¥¡A¦p¥X²{ "The kernel appears to have died.  It will restart automatically" µ¥ª¬ªp®É¡A
¸Ñ¨M¤§¹D¬O¡G

¤£­n¦A³z¹L Anaconda Navigator ¥h°õ¦æ¡A ª½±µ¦Ü \Anaconda3\Scripts ¸Ì±N
jupyter-notebook.exe «ü¦V¤@­Ó±¶®|¡AµM«á¨C¦¸§¡¥Ñ¦¹±¶®|°õ¦æ¡C
¸g´ú¸Õ¹L¦h­Óª©¥»ÁÙÆZºÞ¥Î (ÆF¥ú) ªº¡A¦p¦¹«K¦AµL "No Kernels" ªº§xÂZ¤F¡C
§Ú­Ó¤H§PÂ_À³¸Ó¬O Navigator  ¥h³sµ²¥¦¥»¨­ªº¤l¿ï¶µ®É¡A¦bÀô¹Ò³]©w¤¤¥X¤F°ÝÃD¡C

TOP

¦^´_ 163# zyzzyva
1.) Anaconda3-4.2.0-Windows-x86_64.exe
2.) Anaconda3-4.1.1-Windows-x86_64.exe
¥u­n¦w¸Ë¥H¤W¨âºØ ¤§¥ô¤@¶µ¡A¦b°õ¦æ jupyter notebook
«á¡AÀH·N¶}±Ò *.ipynb ªºÀɮ׮ɡA§¡·|¥X²{ "No Kernels" ªºµ²ªG¡C
§A¥i¸ÕµÛ ¦w¸Ë¥H¤W¥ô¤@¤§ *.exe ¬Ý¬Ý¬O§_¯à¶¶§Q°õ¦æ¡H

TOP

        ÀR«ä¦Û¦b : ­n¤ñ½Ö§ó¨ü½Ö¡D¤£­n¤ñ½Ö§ó©È½Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD