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

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

¦^´_ 13# VBALearner
¬Oªº¡A¨º¬Orequests¼Ò²Õªº¤å¥ó¨S¿ù¡C
¤º«Øªºurllib¼Ò²Õªº¥\¯à¤]®t¤£¦h¡A¦ý¬O§Úı±orequests¤ñ¸û¦n¥Î¤@ÂI¡C

TOP

¦^´_ 9# zyzzyva

³á~ÁÂÁ±zªº±Ð¾Ç¡A§Ú¤é«á·|¦A¶i¤@¨B¤F¸Ñ¡A¥t¥~½Ð°Ý¤@¤U¡A¼Ò²Õºô§}¬O
http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
¨S¿ù§a?
¯u¤ß·PÁ¨C¤@¦ìÄ@·N¤À¨É©Ò¾Ç¡B«ü¾É·s¤âªº¤H!

TOP

¦^´_ 11# c_c_lai
±z¤Ó«È®ð¤F¡A¦³¿³½ì¥i¥H¤@°_¬ã¨s¡C¤]¹w¯¬±z¤â³N¶¶§Q¡A¦­¤é±d´_¡C

TOP

¦^´_ 10# zyzzyva
ÁÂÁ§A¡A
µ¥§Ú²´·ú¤â³N¦n«á¦A¨Ó¬ã¨s¤@µf¡A
«e¨Ç¤é¤l§Ú¹ï Python ÁÙÆZ¼ö°Jªº¡A
©|½Ð§A¦h¥[«ü±Ð¡I

TOP

¦^´_ 8# c_c_lai
¥u­n¦w¸Ërequests´N¥i¥H¤F¡C

TOP

¦^´_ 1# zyzzyva
¸É¤Wµù¸Ñ¡C
  1. #¶×¤J¼Ò²Õ(requests»Ý¥t¥~¦w¸Ë¡A¤]¥i¨Ï¥Îurllib2)
  2. import requests
  3. import time
  4. import os

  5. #¨ú±o·í«e¤é´Á
  6. mydate = time.strftime("%Y/%m/%d")

  7. #±N¦è¤¸¦~Âର¥Á°ê¦~
  8. year = str(int(mydate[0:4])-1911)

  9. #±N¥Á°ê¦~¨ú¥N¤é´Á¤¤¤§¦è¤¸¦~
  10. mydate2 = mydate.replace(mydate[0:4],year)

  11. #os.getcwd()¨ú±o·í«e¸ô®|
  12. setting = os.getcwd() + "\\" + "path.ini"

  13. #Àˬdpath.ini¬O§_¦s¦b¡A­Y¦³«h±Ncsv¦sÀɤ§¸ô®|Ū¤J
  14. if os.path.exists(setting):
  15.     with open(setting, 'r') as r:
  16.         path = r.read()
  17.     #­Ycsv¦sÀɤ§¸ê®Æ§¨¤£¦s¦b«h«Ø¥ß¸ê®Æ§¨
  18.     if not os.path.exists(path):
  19.         os.makedirs(path)

  20. #­Ypath.ini¤£¦s¦b«h±Npath³]¬°ªÅ¦r¦ê
  21. else:
  22.     path = ""

  23. #³]©wheader
  24. headers = {"User-Agent":"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"}

  25. #³]©wurl
  26. url1 = "http://www.twse.com.tw/ch/trading/fund/T86/T86.php"

  27. #³]©wpost¬d¸ß¤§¸ê®Æ
  28. payload1 = {"download": "csv",
  29.             "qdate": mydate2,
  30.             "select2": "ALLBUT0999",
  31.             "sorting": "by_issue"}

  32. #µo¥Xrequest¨Ã±Nºô¯¸¦^ÂФ§¸ê®Æ¦s¤Jres1ÅܼƤ¤
  33. res1 = requests.post(url1, headers=headers, data=payload1, stream=True)

  34. #³]©wcsvÀɮפ§¸ô®|»PÀɦW
  35. fName1 = path + mydate.replace("/","") + ".csv"

  36. #±Nres1ªº¸ê®Æ¼g¤Jcsv¤¤
  37. with open(fName1, 'wb') as f1:
  38.     for chunk in res1.iter_content(1024):
  39.         f1.write(chunk)
½Æ»s¥N½X

TOP

¦^´_ 7# zyzzyva
­è­è§Ú¸Õ¤F¤@¤U¡AOK ¤F¡C
½Ð±Ð¤@¤U§Ú¦³¤U¸ü Python35 ¦ý¬OÁٻݭn«ç¼Ëªº¼Ò²Õ
±ø¥ó¤U¡A¤~¯à§¹¾ã°õ¦æ§Aªþ¤Wªº .py ÀÉ©O¡H
Python ¬O¦³½m²ß¹L¡A¦ýµL¹ê°È§@·~¸gÅç¡A
ÁٽЦh¦h«ü±Ð¡I

TOP

¦^´_ 5# c_c_lai

À³¸Ó¬O¦]¬°§Ú¨S¦³³B²z®É¶¡(¤U¸üªº¤é´Á¬Oª½±µ¨ú·í¤éªº¤é´Á)¡A¦pªG¬O¸ê®ÆÁÙ¨S¥X¨Óªº®É­Ô°õ¦æ¤U¸ü´N·|¥X²{°ÝÃD¡C
½Ð¦b³Ä±ßªº®É¶¡¦A¸Õ¸Õ¬Ý¡C

TOP

¦^´_ 5# c_c_lai

¦A­«·s¤U¸ü¸ÑÀ£ÁY«á¥i¥¿±`°õ¦æ
TKS
¬ã¨sPYTHON¤¤~~

TOP

¦^´_ 3# zyzzyva
Àˬd¥Ø¿ý¤º¤§Àɮפº®e¦p¹Ï¥Ü¡G

TOP

        ÀR«ä¦Û¦b : «Ý¤H°h¤@¨B¡A·R¤H¼e¤@¤o¡A´N·|¬¡±o«Ü§Ö¼Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD