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

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

¦^´_ 41# c_c_lai

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

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

¥»©«³Ì«á¥Ñ 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

¥»©«³Ì«á¥Ñ 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

¦^´_ 38# c_c_lai
¨º­Ó°T®§¤£¼vÅT°õ¦æ¡A¦pªG¤£·Q¬Ý¨ìĵ§i°T®§¥u­n¹³L¤j»¡ªº«ü©wparser´N¥i¥H¤F¡C§âsoup¨º¬q§ï¦¨
soup = BeautifulSoup(res.text, "html. parser")

TOP

¦^´_ 38# c_c_lai


    soup = BeautifulSoup(res.text,"html.parser")

TOP

¦^´_ 37# zyzzyva

TOP

¦^´_ 36# c_c_lai
¨ä¹ê§Ú¤]³£¥u¬O°µÂ²³æªºÀ³¥Î¡A¤@­Ó²³æªº¨Ò¤l(§ì¨ú´Á³f¥~¸ê¥æ©ö¤f¼Æ¥H°µ¬°¥æ©öµ¦²¤ªº°Ñ¦Ò)¡G
ºô§}¡Ghttp://www.taifex.com.tw/chinese/3/7_12_3.asp
°²³]¥Ø¼Ð¬O§ì¨ú¹Ï¤¤¬õ°éªº¼Æ¦r¡G
©T©wªº°_¤â¦¡¤j·§´N¹³³o¼Ë(bs4­n¥t¥~¦w¸Ë¡AÁÙ¦³¤@­Ó¤]«Ü¦n¥Îªº¬Olxml)¡G
  1. import requests
  2. from bs4 import BeautifulSoup

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

  4. res = requests.get(url)

  5. soup = BeautifulSoup(res.text)

  6. tbl = soup.select('.table_f td')

  7. print(tbl[33].text)
½Æ»s¥N½X
¦]¬°¨Ï¥Î¤Frequests©Mbs4¡A¥u­n²µuªº´X¦æµ{¦¡½X´N¥i¥H¹F¨ì§Ú­Ìªº»Ý¨D¡C

TOP

¦^´_ 35# zyzzyva
¨ä¹ê¾Ç²ß¥ô¦óµ{¦¡»y¨¥§¡¦³¤@³q¯f¡A
¦b¾Ç²ß¹Lµ{¤¤¤j®a³£¤F¸Ñ¦U­Ó»yªkªº¨Ï¥Î¡A
¦ý­n±N¥¦­Ì°Â¦b¤@°_À³¥Î©ó¹ê°È­±®É¡A«o©¹©¹¤S¬O¥t¤@¦^¨Æ¡C
¦³¨Ç¤H¦]¦Ó©Ä¨B¤£«e¡A¬Æ¦Ü±ó¤§Â÷¥h¡C
Æ[¹î¨ä­ì¦]¦h¦]µL¹ê¥Îªº½d¨Ò±Ð¾Ç¤Þ¾É¡A¥R¤À¤§¸ê°T´£¨Ñ¡C
¦n¤ñ§Ú¾Ç²ß Excel VBA ¤@¶}©l§Ú¥u¬O¾ÌÂǵۦ³¨ä¥¦µ{¦¡»y¨¥­I´º
¼¶¼g°ò¦¡A¶i¦Ó±q¦U¦ì¤j¤jªº´£°Ý¤¤¤@¨B¤@¨B¦a±´°Q¡BÀ³¥Îªº¡C
¦pªG¤j¤j¯à´£¦C¤@¨Ç¹ê¥Î½d¨Ò¡B»Ý­n®M¥ó¡AÀ³¯d·N¨Æ¶µµ¥¡A
À°§U¤j®a´£¤É»â°ì¨º¤]¬O¥\¼w¤@¥ó°Ú¡I

TOP

¦^´_ 34# moco5360
À³¸Ó­n¬Ý§Aªº»Ý¨D¡G¬Ý§A­n¤U¸üªº¬O¤°»ò¼Ëªº¸ê®Æ¡A°µ¤°»ò¼Ëªº¾ã²z¡A(§R°£­«½Æ¸ê®Æ¤£¤ÓÀ´¡A¬O«ü¦pªG­«½Æ¤U¸ü­n§â¦hªº§R±¼ÁÙ¬O­ì¨Óªº¸ê®Æ´N¦³­«½Æ¡H)
vba§ì¸ê®Æ§Ú¤£¤Ó¼ô¡A¨S¿ìªk°µ¤ñ¸û¡A¤£¹Lpython¦b¤U¸ü¸ê®Æ¨Ó»¡¡A§Ú¦Û¤v¥Î°_¨Ó¬Oı±oÁÙº¡¶¶¤âªº¡C
¦pªG¸ê®Æ¶q¤£¦h¡A´N¥Îpython§â¸ê®Æ§ì¤U¨Ó¡A¦A¥Îexcel³B²z¡A¦pªG¸ê®Æ¦hªº¸Ü¡A¥i¯àÁÙ¬O­n©ñ¨ì¸ê®Æ®w¸Ì¤ñ¸û¦n¡C

TOP

        ÀR«ä¦Û¦b : ¤H¨ÆªºÁ}Ãø»PµZ¿i¡A´N¬O¤@ºØ¦ÒÅç¡C
ªð¦^¦Cªí ¤W¤@¥DÃD