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

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

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-9-7 18:47 ½s¿è

¦^´_ 39# lpk187
¦^´_ 40# zyzzyva
ÁÂÁ§A¡I
½Ð°Ý 3714 ¥Nªíµ§¼Æ¶Ü¡H
¦pªG­nÅã¥Ü Get «áªººô­¶¤º®e¨º¸Ó¦p¦óªí¹F¡H

TOP

¥»©«³Ì«á¥Ñ zyzzyva ©ó 2016-9-7 21:21 ½s¿è

¦^´_ 41# c_c_lai
3714¬O¤µ¤Ñ¥~¸êªº´Á³f¦hªÅ¥æ©ö²b¤f¼Æ¡A´N¬O¹Ï¸Ì¬õ°éªº¦a¤è¡C¤@¯ë§Ú¬O·|ª½±µ¼g¨ìcsvÀɸ̡A³o¼Ëts©Îmc´N¥i¥Hª½±µÅª¨ú¡C

¦pªG­nÅã¥Ü§ì¨ú¦^¨Óªº§¹¾ãºô­¶¡A¥u»Ý­n
  1. import requests

  2. url = 'http://www.taifex.com.tw/chinese/3/7_12_3.asp'

  3. res = requests.get(url)

  4. print(res.text)
½Æ»s¥N½X
BeautifulSoup¨ºÃä¥u¬O¦b°µhtml½Xªº­åªR¡A¤è«K§Ú­Ì§ä¨ì­nªº¸ê®Æ¡C

TOP

¦^´_ 41# c_c_lai

    ªí®æ¥i¥H¥Î pandas ¥h§ì¸Ô²Óªº«ü¥O¥i°Ñ·Ó http://pandas.pydata.org/pandas- ... tml#io-excel-writer
  1. import pandas as pd
  2. import io
  3. url = 'http://www.taifex.com.tw/chinese/3/7_12_3.asp'
  4. dfs = pd.read_html(url, index_col=0)
  5. data=dfs[3][0:][1:]
  6. data.to_excel('test.xlsx')
½Æ»s¥N½X
¤£¹L§ì¦^¨Óªºªí®æ¦³ÂI¿ù¶Ã¡A§Ú¤]¬O­è¶}©l¾Ç¡A§O¤¶·N¡I
¤j®a¤¬¬Û¬ã¨s¡I   :$

TOP

¦^´_ 41# c_c_lai

html¤ñ¸û¦h°ÝÃD¡A ·í§A¦³html5lib / LXML¸ÑªR¾¹ªº°ÝÃD
§A¥i¥H¤U¸ü¥¦
pip install html5lib
easy_install lxml

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-9-8 07:08 ½s¿è

¦^´_ 43# lpk187
ÁÂÁ§A¡I
³o¬O¤£¬O«ü Pandas ®M¥ó©|¥¼¦w¸Ë¡H
½Ð°Ý¤U¸üPandas®M¥ó«á¡A ­n¦p¦ó¥[¤JPandas ®M¥ó¡H
·Pı¤W¤ñ Excel VBA ÁÙ½ÆÂøËç¡C

TOP

¦^´_ 42# zyzzyva
ÁÂÁ§A¡I
°õ¦æ§¹«á¥X¨Óªº¬Oºô­¶­ì©l½X¡A
¦p°ê§Ú·Q­nªº¬O¦p§A¤W¹Ïªºµ²ªG­È¡A
¨º¤S¸Ó¦p¦ó³B²z¡H
§Ú¬O¦b·Q¤F¸Ñ Python ¥¦¬O¦p¦ó¨Ó§¹¦¨¡H

TOP

¦^´_  c_c_lai

html¤ñ¸û¦h°ÝÃD¡A ·í§A¦³html5lib / LXML¸ÑªR¾¹ªº°ÝÃD
§A¥i¥H¤U¸ü¥¦
pip install html ...
lpk187 µoªí©ó 2016-9-8 00:05

¤£¦n·N«ä html5lib / LXML ­n¦p¦ó¤~¯à¤U¸ü¨ì¡H
¤U¸ü«á§Ú¬O¦b¦w¸Ëªº Python 3.5 ªºÀô¹Ò¤U °õ¦æ pip install ¡H
¦ý¬O¥Ø«e§Ú¤£ÃѦb¸ÓDOS Àô¹Ò¤U°õ¦æµ{¦¡¡A¦Ó¬O³z¹L Anaconda ªº
Jupyter Àô¹Ò¤U°õ¦æµ{¦¡¤U¡A¨º¤SÀ³¸Ó­n¦p¦ó¹B§@¡H
¤£¦n·N«ä¤@¤f®ð´£¥X³o»ò¦hªººÃ°Ý¡A¦]µL¤H±Ð¾É¦Û¾Çªº¡A
©Ò¥H©|½Ð¦h¦h¥]²[¡C¦A¦¸¦V§A»¡ÁnÁÂÁÂÅo¡I

TOP

¥»©«³Ì«á¥Ñ lpk187 ©ó 2016-9-8 09:16 ½s¿è

¦^´_ 47# c_c_lai

¦w¸Ë¼Ò¶ô³Ì¦n¦bDOS¤¤¦w¸Ë ¡A¨ä¹ê¦b¦w¸ËPython®É¤j¦h¤w¼g¤JÀô¹ÒÅܼơA¦ý¬O³Ì¦nÁÙ¬O¦b¨äª©¥»¤UªºScripts¸ê®Æ§¨¦w¸Ë¤ñ¸û¦n
¨Ò¦pAnaconda3ª©¥»¤U¡G¥ý¶i¤Jcmd ¶i¤JDOS «á¥´¤Jcd  C:\Anaconda3\Scripts    <<==¨Ì§A¹ê»Ú¸ê®Æ§¨¬°·Ç
¦w¸Ë«e¡A¥ý¤É¯Åpip  »yªk¡G"pip install --upgrade pip"
pandas¡Gpip install pandas
¦w¸Ëpandasªº¦P®É¥¦¦n¹³¤]·|À°§A¦w¸Ë

html5lib¤]¬Opip¡Gpip install html5lib ¡A­Y¤w¸g¦³¦w¸Ë¤F¡A¨º´N¤É¯Å¥¦ pip install -U html5lib -U¬O¤É¯Åªº·N«ä U ¥²¶·¤j¼g

¦Ü©ó lxml ¤j¦h¤w¸g¦w¸Ë¡A¦ýª©¥»®e©ö¥X¿ù¡A©Ò¥H­n¥ý¤Ï¦w¸Ë  conda remove lxml
lxml ¥Îpip¤£¦n¦w¸Ë¡A©Ò¥H§Ú¬O¥Î easy_install ¦w¸Ëªº  easy_install lxml

¨ä¥Lª©¥»¤]¬O¤@¼Ë»Ý­n¨ì¨ä¥Ø¿ý(Scripts)¦w¸Ë¤ñ¸û§´·í

TOP

¦^´_ 48# lpk187
«D±`·PÁ¡A§Ú¨Ó¾ÇµÛ¸Õ¸Õ¦w¸Ë¬Ý¬Ý¡A
§Ú¬Ý¤F Anaconda ªº»¡©ú³£¨S´£¤Î¡A©Ò¥H¦Ü¤µÁÙ¬O¥®¨àªì¯Å¥Í¡A
ºF·\ºF·\¡I
¨º»ò Python 3.5 ªºÀô¹Ò¤U¬O§_¨Ì»Ý¦p¦P  Anaconda Script ¤@¼Ë
»Ý­n°õ¦æ Pip ªº®M¥ó¨Ó¦w¸Ë¤É¯Å¡H

TOP

¦^´_ 48# lpk187
­×¥¿®M¥ó«á¡A°õ¦æ¤§µe­±¦p¤U¡A¬Ý°_¨Ó¬O OK¡A
¦ý«o¨S¬Ý¨£ Test.xlsx ÀɮסH¥¦·|²£¥Í¦b­þ¸Ì¡H
³o¼Ëªºµe­±Åã¥Ü¬OÄÝ¥¿½T¶Ü¡H
ÁÂÁ§Aªº«ü¾É¡I

TOP

        ÀR«ä¦Û¦b : ¶¢¤HµL¼Ö½ì¡A¦£¤HµL¬O«D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD