Pythonã®CGIã¹ã¯ãªããã§è¨ºæã¡ã¼ã«ã¼ã®è¨ºæçµæãè¤æ°åæã«åå¾ãã
診æã¡ã¼ã«ã¼ã®è¤æ°ã®è¨ºæçµæãããã¹ãã§è¿ãCGIã¹ã¯ãªãããçµæãHTMLããæ½åºããã®ã«BeautifulSoupã©ã¤ãã©ãªã使ç¨ããã
追è¨ï¼ 2010/11/02 HTMLæ§é ã®å¤åã«ä¼´ã£ã¦ã½ã¼ã¹ãå¤æ´ãã¾ããã
#! /usr/bin/python2.6 # coding: utf-8 import cgi import time import urllib from BeautifulSoup import BeautifulSoup fs = cgi.FieldStorage() url = 'http://shindanmaker.com/' def resp(user, nums): rlst = [] for n in nums: data = urllib.urlencode({'u': user}) cont = urllib.urlopen(url + n, data).read() soup = BeautifulSoup(cont) # 2010/11/02 #title = soup.find('div', {'class':'shindantitle'}).find('h1').next.next title = soup.find('div', {'class':'shindantitle2'}).find('a').contents[0] result = soup.find('div', {'class':'result'}).find('div').contents[0].strip() rlst.append('\t'.join([title, result])) time.sleep(2) # wait 2 seconds per request print '\n'.join(rlst) def main(): print 'Content-Type: text/plain; charset-utf-8' print '' try: user = fs.getvalue('user') nums = fs.getvalue('nums').split(',') resp(user, nums) except: print 'bad request' main()
å®è¡çµæ
ãã¼ã«ã«ã«ãµã¼ããç«ã¡ä¸ãã¦å®è¡ç¢ºèªã
ä¾ï¼ /cgi-bin/shindan.py?user=brainfs&nums=43421,43401,5105,18312 ã®ã¬ã¹ãã³ã¹
ãã¯âãã£ãã¼(ææç) brainfsã¯ãçé MAX161km/hãコï¾ï¾ï¾ï½°ï¾ï¼£ãï½½ï¾ï¾ï¾ ï¼¥ã§ã決ãçã¯å¤åéï¼ã®SFFãã§ãã 表æ ã£ãã¼ brainfsã¯ãï¼ï½ï½¥_ï¿£)ãã§ãã äºæ¬¡å 女ä½åãã¦ãã£ãã¼ brainfsãäºæ¬¡å 女ä½åããã¨ãæã¯ã¯ã³ãã¼ã¹ã§ãã¤ãç®ã§è¶é«ªã®ãã³ã°ã®ãã¤ã³ãã¼ã«ã§å è³+å å°¾ã§ãã£ã¡ããã¡ãããªæãã®ãã£ã©ãã®ããã ããªããæ¼¢å75æåã§è¡¨ãã¾ãã â«brainfsãæ¼¢å75æåã§è¡¨ãã¨âè¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¸è¶ ç¡ç