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

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

¦^´_ 70# c_c_lai
Screenshot_4.png
tmpList¨S¦³©w¸q¡C
­n°O±o¦bfunction¥~­±¥[¤W¡G
myDict = {}
myList = []
tmpList = []
µM«á¨º­Óprint(myUrl)¥i¥Hµù¸Ñ±¼¡C

TOP

¦^´_ 71# zyzzyva

TOP

¦^´_ 71# zyzzyva

TOP

¦^´_ 73# c_c_lai
¸òget_detail©ñªº¦ì¤l¤]¦³Ãö«Y(call functionªº®É­Ôpython´N·|¥h§ä¡A¦pªGÁÙ¨S©w¸q´N·|¦³°ÝÃD)¡C
§ï¤F¤@­Óbug(¤§«e·|§}¨S³B²z¨ì)¡A¥[¤W¿é¥Xªº³¡¥÷¡C
¥Ø«eªºcode§Ú¾ã²z¤F¤@¤U¡A±z¥Î³o­Ó¦A´ú¸Õ¬Ý¬Ý¡C
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import csv


  4. def get_detail(url, s):
  5.     print(url)
  6.     res = s.get(url)
  7.     res.encoding = 'utf-8'
  8.     soup = BeautifulSoup(res.text, 'lxml')
  9.     detail = soup.find_all('td', 'church_detail')
  10.     for ddd in detail[0].stripped_strings:
  11.         if '¦^³ø¸ê®Æ¿ù»~ >' in ddd:
  12.             continue
  13.         else:
  14.             tmpList.append(ddd)

  15.     for i, s in enumerate(tmpList):
  16.         if s == "":
  17.             continue
  18.         elif any(x in s for x in ['¹q¶l', 'ºô§}', '©v¬£', '¥À·|']):
  19.             myDict[s.replace('¡G', '')] = tmpList[i+1]
  20.         elif '·|§}' in s:
  21.             myDict[s.split('¡G')[0]] = (s.split('¡G')[1] + tmpList[i+1])
  22.         else:
  23.             try:
  24.                 myDict[s.split('¡G')[0]] = s.split('¡G')[1]
  25.             except:
  26.                 pass
  27.     myList.append(myDict)


  28. myDict = {}
  29. myList = []
  30. tmpList = []
  31. s = requests.session()

  32. for i in range(1, 2):
  33.     url = 'http://church.oursweb.net/slocation.php?w=1&c=TW&a=&t=&p=' + str(i)
  34.     res = s.get(url)
  35.     res.encoding = 'utf-8'
  36.     soup = BeautifulSoup(res.text, 'lxml')

  37.     for d in soup.select('a[href^="church.php?pkey"]'):
  38.         myUrl = 'http://church.oursweb.net/' + d.get('href')
  39.         get_detail(myUrl,s)
  40.         myDict = {}

  41.     i += 1

  42. with open('gospel2.csv', 'a', new='', encoding='utf-8') as f:
  43.         fieldnames = ['«ØÀÉ ID', '¤¤¤å¦WºÙ', '­^¤å¦WºÙ', '¤ÀÃþ', '©v¬£', '¥À·|', 'ºô§}', '°ê§O°Ï°ì', '³]¥ß®É¶¡', '­t³d¤H', '¹q¸Ü', '¶Ç¯u', '¹q¶l', '·|§}', '³q°T³B']
  44.         w = csv.DictWriter(f, fieldnames)
  45.         w.writeheader()
  46.         w.writerows(myList)
½Æ»s¥N½X

TOP

¦^´_ 74# zyzzyva

TOP

¦^´_ 75# c_c_lai
¸ò¦­¤W¤@¼Ëªº°ÝÃD¡A¤£ª¾¹D¬ObugÁÙ¬O¦³¯S®í­ì¦]¡A½×¾Â¤£¯à¿é¤J¡u½u¡vªº­^¤å¡C

³oÃä§ï¤@¤UÀ³¸Ó´N¥i¥H¤F¡C

TOP

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

¦^´_ 76# zyzzyva

ÁÂÁ§A¥Î¤ßªº«ü¾É¡I

TOP

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

¦^´_ 77# c_c_lai
³o¼ËÀ³¸Ó¬O¦³work¤F¡A¥Îexcel¶}¬Ý¬Ý¡A¦pªG¬O¶Ã½X­n¥Îµ§°O¥»¶}°_¨Ó¦sÀɤ@¤U¦A­«¶}¡C

TOP

¦^´_ 78# zyzzyva
µ§°O¥»¤º¥ç¬O¤@°ï¶Ã½X¡A¦³¨S¦³¿ìªk¦sÀÉ®ÉÂন Big5 ½X¤§Ãþ
¦p Unicode µ¥¡A§_«h¨C¦¸³£»Ý¥t§ä NotePad++ µ¥¤u¨ãÂà½X
¹ê¦b¤Ó³Â·Ð¤F¡C

TOP

¦^´_ 79# c_c_lai
©Ç©Ç¡A§Úªº¥i¥H»¡¡A±zªº¦bipython¸Ì¥i¥HÅã¥Ü¥i¬O¥Îµ§°O¥»¶}¤Ï¦Ó¤£¦æ¡H
½s½Xªº°ÝÃD§Ú¤]¤@ª½«ÜÀYµh¡A·|¥Îutf-8¬O¦]¬°¸ê®Æ¸Ì¦³¤@¨Ç¤£¬Obig5¡A¹³¡u¥­瀬¸q¾ð ªª®v¡vªº¡u瀬¡v¡C
¦b³Ì«áwith open¨ºÃ䪺encoding§ï¦¨encoding='utf-8-sig'¸Õ¸Õ¬Ý¡C

TOP

        ÀR«ä¦Û¦b : ¥¬¬I¦p¼½ºØ¡A¥HÅw³ß¤ß´þ¼íºØ¤l¡A¤~·|µoªÞ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD