- ©«¤l
- 109
- ¥DÃD
- 1
- ºëµØ
- 0
- ¿n¤À
- 116
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- 2007
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2016-8-4
- ³Ì«áµn¿ý
- 2018-10-22
|
¦^´_ 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- import requests
- from bs4 import BeautifulSoup
- import csv
- def get_detail(url, s):
- print(url)
- res = s.get(url)
- res.encoding = 'utf-8'
- soup = BeautifulSoup(res.text, 'lxml')
- detail = soup.find_all('td', 'church_detail')
- for ddd in detail[0].stripped_strings:
- if '¦^³ø¸ê®Æ¿ù»~ >' in ddd:
- continue
- else:
- tmpList.append(ddd)
- for i, s in enumerate(tmpList):
- if s == "":
- continue
- elif any(x in s for x in ['¹q¶l', 'ºô§}', '©v¬£', '¥À·|']):
- myDict[s.replace('¡G', '')] = tmpList[i+1]
- elif '·|§}' in s:
- myDict[s.split('¡G')[0]] = (s.split('¡G')[1] + tmpList[i+1])
- else:
- try:
- myDict[s.split('¡G')[0]] = s.split('¡G')[1]
- except:
- pass
- myList.append(myDict)
- myDict = {}
- myList = []
- tmpList = []
- s = requests.session()
- for i in range(1, 2):
- url = 'http://church.oursweb.net/slocation.php?w=1&c=TW&a=&t=&p=' + str(i)
- res = s.get(url)
- res.encoding = 'utf-8'
- soup = BeautifulSoup(res.text, 'lxml')
- for d in soup.select('a[href^="church.php?pkey"]'):
- myUrl = 'http://church.oursweb.net/' + d.get('href')
- get_detail(myUrl,s)
- myDict = {}
- i += 1
- with open('gospel2.csv', 'a', new='', encoding='utf-8') as f:
- fieldnames = ['«ØÀÉ ID', '¤¤¤å¦WºÙ', '^¤å¦WºÙ', '¤ÀÃþ', '©v¬£', '¥À·|', 'ºô§}', '°ê§O°Ï°ì', '³]¥ß®É¶¡', 't³d¤H', '¹q¸Ü', '¶Ç¯u', '¹q¶l', '·|§}', '³q°T³B']
- w = csv.DictWriter(f, fieldnames)
- w.writeheader()
- w.writerows(myList)
½Æ»s¥N½X |
|