Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active December 14, 2015 11:18
Show Gist options
  • Save allieus/5077670 to your computer and use it in GitHub Desktop.
Save allieus/5077670 to your computer and use it in GitHub Desktop.
국가 지정 수리과학연구정보센터, 수학용어 검색 스크립트
# coding: utf-8
import sys
from urllib import urlencode, urlopen
from BeautifulSoup import BeautifulSoup
def search(term):
params = urlencode({
'mode': 'list',
'ftype': 'eng_term',
'fstr': term,
})
url = 'http://mathnet.kaist.ac.kr/mathnet/math_list.php?%s' % params
html = urlopen(url).read()
soup = BeautifulSoup(html)
text_list = [tag.text for tag in soup.findAll('td', {'class':'list_row'})]
if len(text_list) > 0:
max_len = max(len(text_list[i]) for i in range(0, len(text_list), 2))
print_format = u'%' + str(max_len) + u's : %s'
for i in range(0, len(text_list), 2):
print print_format % tuple(text_list[i:i+2])
else:
print 'no result.'
if __name__ == '__main__':
try:
term = sys.argv[1]
except IndexError:
print >>sys.stderr, 'usage> %s <term>' % sys.argv[0]
sys.exit(1)
else:
search(term)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment