def get_items(string_to_search): data = get_data_from_server(string_to_search) soup = BeautifulSoup(''.join(data)) list = [] table = soup.find('table',{'class':'mpitems'}) rows = deque(table.findAll('tr')) rows.popleft() for theItem in rows: cols = theItem.findAll('td',recursive=False) newItem = Item() image = cols[0].find('img') if image: newItem.image=(image['src']) titleSpan = cols[1].find('span',{'class':'br_item_title'}) if titleSpan: newItem.title = unicode(titleSpan.a.string) newItem.link='http://www.discogs.com'+titleSpan.a['href'] newItem.fromPage='Discogs' priceSpan = cols[4].find('span',{'class':'price'}) if priceSpan: newItem.price=unicode(priceSpan.string) list.append(newItem) return list
def parse_data_from_server(html_data): soup = BeautifulSoup(html_data) list = [] items = soup.findAll('div', {'class':'item'}) for theItem in items: newItem = Item() name = theItem.find('a',{'class':'nombre sin_subrayar'}) if name: newItem.title=unicode(name.string) newItem.price=''#get_price(theItem) newItem.link="http://www.todocoleccion.net"+name['href'] newItem.image=theItem.find('div',{'class':'foto'}).img['src'] newItem.fromPage='TodoColeccion' list.append(newItem) return list