import requests, bs4, urllib, sys, re, math term = str(sys.argv[1]) query = urllib.parse.quote_plus(term) url = 'https://search.naver.com/search.naver' url2 = '?sm=tab_hty.top&where=nexearch&query=' + query + '&oquery=' + query url = url + url2 resp = requests.get(url) resp.raise_for_status() resp.encoding='UTF-8' html = resp.text bs = bs4.BeautifulSoup(html, 'html.parser') _list = bs.select('ul._related_keyword_ul li a') if len(_list) == 0 : print( "nTong" + "\t" + term + "\t" + "\t" + str(len(_list)) + "\t" + str(0) ) else : for i in range(len(_list)) : aff_terms = _list[i].getText().strip() print( "nTong" + "\t" + term + "\t" + aff_terms + "\t" + str(len(_list)) + "\t" + str(i+1) )