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

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

¦^´_ 63# zyzzyva
·PÁ¡I ²×©ó¥Ûºh¶}ªá¤F¡I

³t«×«D±`§Ö¡A ¦A¨Ó¦h­Ó¦n½d¨Ò¾Ç²ß¾Ç²ß¡C
ÁÂÁÂÅo¡I

TOP

¥»©«³Ì«á¥Ñ zyzzyva ©ó 2016-9-11 08:06 ½s¿è

¦^´_ 62# c_c_lai
¥Û¨I¤j®ü...¦]¬°¯uªº¨S¦³¸ê®ÆXD
¤£ª¾¹D¬°Ô£µ{¦¡½X¶K¤Wªº®É­Ô½×¾Â¨t²Î·|­×§ï¡A¤U­±³o¬q
data = soup.find_all('tr',['tb__a', 'tb__b'])¡AÀ³¸Ó¬O

­×§ï¤@¤UÀ³¸Ó´N¥¿±`¤F¡C

TOP

¦^´_ 61# zyzzyva
½Ð±Ð print(d.text) ¥¦·|±q­þ¸ÌÅã¥Üµ²ªG¡H
§Ú«ö¤F Shift Enter «á§Y¥Û¨I¤j®ü¡AÁÂÁ§A¡I

TOP

«e´X¤Ñc¤j¦^ÂЪº®É­Ô¦³¶K¤Fvbaªºcode¡AÅý§Ú·Q¨ì¦pªG§ä¤@¨Ç¦bexcelª©ªº°ÝÃD¥Îpython¸Õ°µ¬Ý¬Ý¡A¤]³\¦³¿³½ìªºªB¤Í¥i¥H¬Û¤¬°Ñ·Ó¡C
§ì¸ê®Æ«Ü¦h°ÝÃD·Q°_¨Ó¤£§xÃø¡A¦ý¹³§Ú³£¥u°µÂ²³æªºÀ³¥Î¡A¸gÅ禳­­¡A¯u­n°µ¤ñ¸û§¹¾ãªº¸ê®Æª¦¨ú¡A¼²À𪺲Ӹ`°ÝÃD·Q¥²«D±`¦h¡C
³Ìªñ¤ñ¸û¦³®É¶¡¡A­è¦n¶X³o­Ó¾÷·|½m²ß¤@¤U¡CÅwªïª©¤WªºªB¤Í¤@°_¬ã¨s°Q½×¡A¦pªG¦³¨ä¥L¨Ï¥Îpythonªº«e½ú¡A¤]½Ð¤£§[µ¹§Ú¤@¨Ç´£ÂI¸ò«Øij¡C
¤@¶}©l§Ú·Q´N±q³o½g¶}©lhttp://forum.twbts.com/thread-18259-1-2.html¡C
GBKEEª©¤j¤w¸g¥Îvba´£¨Ñ¤F«Ü¦nªº¸Ñ¨M¤è®×¡A¦ý­Y¬O·Q´«­Ó¤f¨ýÁÙ¬O¥i¥H¥Îpython¸Õ¸Õ¬Ý§â¸ê®Æª¦¨ú¤U¨Ó¡C

ºô§}ºô§}¡Ghttp://church.oursweb.net/slocation.php?w=1&c=TW&a=&t=&p=

ºô­¶¬Ý°_¨Ó¨S¦³¤°»ò©_©_©Ç©Çªºjavascript¡A¦pªG¥u¬O­n§ì¹Ï¤ù¤¤ªºÂ²©ö¸ê®Æ¡A¨º¥u­n¡G
  1. #·Ç³Æ¤u¨ã
  2. import requests
  3. from bs4 import BeautifulSoup

  4. #«Ø¥ß¤@­Ósession
  5. s = requests.session()

  6. for i in range(11,14):
  7.     #ºô§}Åܰʪº¥u¦³³Ì«á¤@­Ó¼Æ¦r¡A¦@286­¶¡A¥Îrange(1,287)´N¥i¥H§â©Ò¦³¼Æ¦r¶]¹L¤@¦¸
  8.     #´ú¸Õ®É½Ð¤£­n¶]¤Ó¦h­¶¡A¥Î(1,3)¡B(11,14)¡B(280,283)¤§Ãþªº´N¦n
  9.     url = 'http://church.oursweb.net/slocation.php?w=1&c=TW&a=&t=&p=' + str(i)
  10.     res = s.get(url)
  11.     #­Y¦¬¨ìªºres¤å¦r¬°¶Ã½X´N¥[­Óencoding
  12.     res.encoding = 'utf-8'
  13.     soup = BeautifulSoup(res.text, 'lxml')
  14.         
  15.     #¨ú±o¸ê®Æ¡A§Ú­Ì­nªº¸ê®Æ³£¦s¦b³o¨âºØtr¸Ì   
  16.     data = soup.find_all('tr',['tb__a', 'tb__b'])

  17.     #±N¸ê®Æ¦L¥X
  18.     for d in data:
  19.         print(d.text)
  20.         
  21.     i += 1
½Æ»s¥N½X
¨º¦pªG­n¦¬¶°¸Ô²Ó¸ê®Æ©O¡H¨º´N­n¨ú±o¨C­¶¸Ìªº¦U­Ó±Ð·|ªº³sµ²¡A¤@­Ó¤@­Ó¶i¥hª¦¨ú¡C

TOP

¦^´_ 57# lpk187
¦^´_ 58# zyzzyva
À³¥Î Pandas ¸Õ¥Xµ²ªG¤F¡A
dfs[3][0:][1:] ªº [3] §Y¬°«ü "²Ä¤T­Ó Table" ¤§·N¡C

TOP

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

¦^´_ 57# lpk187
¦^´_ 58# zyzzyva
ipython ªº¸Ü´N¦p zyzzyva ¤j¤j©Ò»¡ªº¡A
·|¦s¦b¦b C:\Users\ µn¤J¤¤¨Ï¥ÎªÌ©³¤U¡C
¦b¦¹¦V§A­Ì¾Ç¨ì¤F¤£¤Ö Python ªº¦³Ãöª¾ÃÑ¡A
³o¥ç¬O«e°}¤l§Ú¬°¦ó±N Python °±Â\ªº½t¬G¡A
ÁÂÁ§A­ÌËç¡I

TOP

¦^´_ 54# c_c_lai
³q±`§Ú³£¥u»Ý­nºô­¶¸Ì¤Ö¼Æªº´X­Ó¼Æ¦r¡A©Ò¥H¤]¨S¦³»{¯u¬ã¨s¹Lªí®æªº§¹¾ã§ì¨ú¡A³ovbaªºcode¬Ý°_¨Ó¤w¸g«Ü²¼ä¤F¡A
¶]¥X¨Óªº®ÄªG¤]«Ü¦n¡A¦pªG¬O­n©ñ¨ìexcel¸Ì¡A§Ú·|ª½±µ¥Î±zªºcode¡CL¤j´£ªºpandas¥i¥H¹F¨ìÃþ¦üªº®ÄªG¡A¦ý¬O¹³³oºØ®æ¦¡¤ñ¸ûÂøªºÁÙ¬O­n°µ½Õ¾ã¡A
¦A©ñ¨ìexcel¸ÌÀY¥i¯àÁÙ¨S¦³³o­Óº}«G¡C

TOP

¦^´_ 50# c_c_lai


    ©Ò²£¥ÍªºÀÉ®×·|¦b³o­Ó©ÒÀx¦sµ{¦¡½X¤Uªº¸ê®Æ§¨¥X²{
¥Hjupyter ¨Ó»¡¤@¯ë³£¦b"¤å¥ó"¸ê®Æ¤¤

TOP

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

¦^´_ 52# zyzzyva
¦^´_ 43# lpk187
¤º®e¬O¡H

TOP

¦^´_ 49# c_c_lai


    ¬Oªº¤@¼Ë¶i¤J¨ìpython3.5¸ê®Æ§¨ªºScripts¸ê®Æ§¨¶i¦æ ¦w¸Ë  
­Y¬O¦b¨ä¥Lªº¸ê®Æ§¨©Î®Ú¥Ø¿ý¤U¦w¸Ë¡A¤ñ¸û·|¿ù¶Ã¡A¨ä¦]¬O¦w¸Ë¦h­Óª©¥»ªº¶}«Y¡I
¦³®Épip¤£¯à¤U¸ü¦w¸Ë¥i¥H¹Á¸Õ¨ä¥L¦w¸Ë¤èªk ¨Ò¦p¥Î easy_install ¦w¸Ë©ÎªÌ°Ñ¦Ò ¨ä¼Ò¶ôªº©xºô»¡©ú

TOP

        ÀR«ä¦Û¦b : ¤f»¡¤@¥y¦n¸Ü¡A¦p¤f¥X½¬ªá¡F¤f»¡¤@¥yÃa¸Ü¦p¤f¦R¬r³D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD