Subversion Repositories SmartDukaan

Rev

Rev 5401 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5401 Rev 6168
Line 23... Line 23...
23
    
23
    
24
    def getPhones(self):
24
    def getPhones(self):
25
        product_prices = []
25
        product_prices = []
26
        
26
        
27
        for div in select(self.soup, "div.product_div"):#self.soup.findAll('div', {'class': 'product_div'}):
27
        for div in select(self.soup, "div.product_div"):#self.soup.findAll('div', {'class': 'product_div'}):
28
            
-
 
29
            anchor = div.find('p', {'class': 'product_title'})('a')[0]
-
 
30
            name = str(anchor['title'].strip())
-
 
31
            
-
 
32
            if name.endswith(' Mobile Phone'):
-
 
33
                name = name.replace(' Mobile Phone', '')
-
 
34
            
-
 
35
            url = str(anchor['href'].strip())
-
 
36
            price = removePriceFormatting(str(div.findAll('span', {'class': 'product_new_price'})[0].string.strip()))
-
 
37
            
-
 
38
            try:
28
            try:
39
                product_prices.append({
-
 
40
                        'name': name, 
-
 
41
                        'price': price,
-
 
42
                        'source': 'homeshop18', 
29
                anchor = div.find('p', {'class': 'product_title'})('a')[0]
43
                        'in_stock': 1, 
-
 
44
                        'product_url': url
30
                name = str(anchor['title'].strip())
45
                    })
-
 
46
                
31
                
-
 
32
                if name.endswith(' Mobile Phone'):
-
 
33
                    name = name.replace(' Mobile Phone', '')
-
 
34
                
-
 
35
                url = str(anchor['href'].strip())
-
 
36
                price = removePriceFormatting(str(div.findAll('span', {'class': 'product_new_price'})[0].string.strip()))
-
 
37
                
-
 
38
                try:
-
 
39
                    product_prices.append({
-
 
40
                            'name': name, 
-
 
41
                            'price': price,
-
 
42
                            'source': 'homeshop18', 
-
 
43
                            'in_stock': 1, 
-
 
44
                            'product_url': url
-
 
45
                        })
-
 
46
                    
47
            except UnicodeEncodeError as e:
47
                except UnicodeEncodeError as e:
48
                print 'Unicode Error', e, name
48
                    print 'Unicode Error', e, name
49
                name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
49
                    name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
50
                print name_ascii
50
                    print name_ascii
51
                product_prices.append({
51
                    product_prices.append({
52
                        "name": str(name_ascii), 
52
                            "name": str(name_ascii), 
53
                        "price": str(price),
53
                            "price": str(price),
54
                        'source': 'homeshop18',
54
                            'source': 'homeshop18',
55
                        "in_stock": 1, 
55
                            "in_stock": 1, 
56
                        "product_url": str(url)
56
                            "product_url": str(url)
57
                    })
57
                        })
-
 
58
            except Exception as e:
58
        
59
                print e
59
        return product_prices
60
        return product_prices
60
    
61
    
61
    def getNextUrl(self):
62
    def getNextUrl(self):
62
        pagination_links = self.soup.find('div', {'class': 'pagination'}).findAll('span')
63
        pagination_links = self.soup.find('div', {'class': 'pagination'}).findAll('span')
63
        
64