import requests, bs4, urllib, sys, re, math from urllib import parse term = str(sys.argv[1]); query = urllib.parse.quote_plus(term) targetUrl = "https://search.shopping.naver.com/search/all.nhn?origQuery=" + query + "&pagingIndex=1&pagingSize=80&viewType=list&sort=rel&frm=NVSHTTL&query=" + query resp = requests.get(targetUrl) resp.raise_for_status() resp.encoding='UTF-8' html = resp.text bs = bs4.BeautifulSoup(html, 'html.parser') _list = bs.select('div.co_relation_srh ul li a') if len(_list) == 0 : print( "nShop" + "\t" + term + "\t" + "\t" + str(len(_list)) + "\t" + str(0) ) else : for i in range(len(_list)) : aff_terms = _list[i].getText().strip() print( "nShop" + "\t" + term + "\t" + aff_terms + "\t" + str(len(_list)) + "\t" + str(i+1) )