{{{ # -*- coding: cp949 -*- daumUrl = "http://apis.daum.net/search/book?%s" naverUrl = "http://openapi.naver.com/search?%s" daumParams = { "apikey" : "9382530ef3abb0588bb463e07259644917e2dd45", "target" : "meta", } naverParams = { "key" : "6f4ad5dbec8f118d6869767b9fbcefe4", "target" : "book" } allResult = [] # ( ['Daum'/'Naver'], title, price, level ) ... def getXmlTitle(title): daumParams['q'] = title naverParams['query'] = title.decode('cp949').encode('utf-8') import urllib daumResult = urllib.urlopen(daumUrl % urllib.urlencode(daumParams)).read() naverResult = urllib.urlopen(naverUrl % urllib.urlencode(naverParams)).read() import BeautifulSoup daumBook = BeautifulSoup.BeautifulSoup(daumResult) naverBook = BeautifulSoup.BeautifulSoup(naverResult) return (daumBook, naverBook) def getXmlAuthor(author): daumParams['author'] = author naverParams['d_auth'] = author.decode('cp949').encode('utf-8') import urllib daumResult = urllib.urlopen(daumUrl % urllib.urlencode(daumParams)).read() naverResult = urllib.urlopen(naverUrl % urllib.urlencode(naverParams)).read() import BeautifulSoup daumBook = BeautifulSoup.BeautifulSoup(daumResult) naverBook = BeautifulSoup.BeautifulSoup(naverResult) return (daumBook, naverBook) if __name__ == '__main__': print '°Ë»öÇÒ Á¦¸ñÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä' title = raw_input() daumRsult = [] # ( ['Daum'], title, price, author) ... naverResult = [] # ( ['Naver'], title, price, author) ... daumRsult, naverResult = getXmlTitle(title) for it in daumRsult.findAll('item'): allResult.append( ('Daum', it.find('title').contents[0].encode('cp949'), it.find('sale_price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 1) ) daumRsultL2, naverResultL2 = getXmlAuthor(it.find('author').contents[0].encode('cp949')) for it in daumRsultL2.findAll('item'): allResult.append( ('Daum', it.find('title').contents[0].encode('cp949'), it.find('sale_price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 2) ) for it in naverResultL2.findAll('item'): allResult.append( ('Naver', it.find('title').contents[0].encode('cp949'), it.find('price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 2) ) for it in naverResult.findAll('item'): allResult.append( ('Naver', it.find('title').contents[0].encode('cp949'), it.find('price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 1) ) daumRsultL2, naverResultL2 = getXmlAuthor(it.find('author').contents[0].encode('cp949')) for it in daumRsultL2.findAll('item'): allResult.append( ('Daum', it.find('title').contents[0].encode('cp949'), it.find('sale_price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 2) ) for it in naverResultL2.findAll('item'): allResult.append( ('Naver', it.find('title').contents[0].encode('cp949'), it.find('price').contents[0].encode('cp949'), it.find('author').contents[0].encode('cp949'), 2) ) # allResult.sort(key=lambda d: int(d[2])) # ,reverse=True) for r in allResult: print '[ ·¹º§:', r[4],']', r[0], '[ °¡°Ý:', r[2], ']', r[1], '[ ÀúÀÚ:', r[3], ']' }}}