Blame | Last modification | View Log | RSS feed
'''Created on 19-Sep-2011@author: Varun Gupta'''from BaseScraper import BaseScraperfrom BeautifulSoup import BeautifulSoupfrom Utils import removePriceFormattingimport jsonclass AdexmartScraper(BaseScraper):def __init__(self):BaseScraper.__init__(self)self.url = Noneself.id = Nonedef setUrl(self, url):self.url = urldef scrape(self):response = BaseScraper.read(self, self.url)html = json.loads(response)['products']self.soup = BeautifulSoup(html)self.phones = Nonedef getPhones(self):phones = []for li in self.soup.find('ul', {'class': 'clear'})('li'):anchor = li.find('a', {'class': 'product_img_link'})name = anchor['title'].strip()product_url = anchor['href']price = li.find('span', {'class': 'price'}).string.strip()in_stock = 1 if li.find('span', {'class': 'availability'}).string.__str__().strip() == 'Available' else 0phones.append({'name': name,'price': removePriceFormatting(price),'source': 'adexmart','product_url': product_url,'in_stock': in_stock})self.phones = phonesreturn phonesdef getNextUrl(self):return Noneif __name__ == '__main__':scraper = AdexmartScraper()scraper.setUrl('http://www.adexmart.com/modules/coremanager/modules/filtersearch/filtersearch.json.php?act=filter&ident=16&page=1&perpage=1000&orderby=newest&orderway=desc')scraper.scrape()print scraper.getPhones()