 #!/usr/bin/python
 # -*- coding: utf-8 -*-
import urllib
from BeautifulSoup import BeautifulSoup as bsoup

serviceUrl = 'http://auctions.search.yahoo.co.jp/search?'
keyword = input('Input Keywords(Devided by a plus):')
page = input('Which Page of the Result Do You Want:')
page = str((int(page)-1)*20 + 1)

url = serviceUrl + 'p=' + keyword + '&' + 'b=' + page
html = urllib.urlopen(url)
start = 0
data = ''
for line in html:
	lineStr = line.decode('utf-8')
	if(start==0):
		if '<!-- SET01 -->' in lineStr:
			start = 1
	else:
		data = data + lineStr
tagList = bsoup(data)
aTags = tagList('a')
dedup = 0
for tag in aTags:
	resUrl = tag.get('href',None)
	if '/jp/auction/' in resUrl and dedup%2==0:
		probe = 0
		html = urllib.urlopen(resUrl)
		marks = ["評価制限","あり","なし"]
		for line in html:
			lineStr = line.decode('utf-8')
			if marks[0].decode('utf-8') in lineStr:
				probe = 1
			if marks[1].decode('utf-8') in lineStr and probe==1:
				break
			if marks[2].decode('utf-8') in lineStr and probe==1:
				print('A Satisfying Res:',resUrl)
				break
	dedup = dedup + 1
	

  
