Subversion Repositories SmartDukaan

Rev

Rev 4039 | Rev 4199 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4039 Rev 4198
Line 3... Line 3...
3
 
3
 
4
@author: Varun Gupta
4
@author: Varun Gupta
5
'''
5
'''
6
from BeautifulSoup import BeautifulSoup
6
from BeautifulSoup import BeautifulSoup
7
from BaseScraper import BaseScraper
7
from BaseScraper import BaseScraper
-
 
8
from Utils import removePriceFormatting
8
 
9
 
9
class InfibeamScraper(BaseScraper):
10
class InfibeamScraper(BaseScraper):
10
    
11
    
11
    def __init__(self):
12
    def __init__(self):
12
        self.url = None
13
        self.url = None
Line 25... Line 26...
25
 
26
 
26
            name = li.findAll('span', {'class': 'title'})[0].string
27
            name = li.findAll('span', {'class': 'title'})[0].string
27
            try:
28
            try:
28
                price = li.findAll('div', {'class': 'price'})[0].findAll('span', {'class': 'normal'})[0].string
29
                price = li.findAll('div', {'class': 'price'})[0].findAll('span', {'class': 'normal'})[0].string
29
            except IndexError:
30
            except IndexError:
30
                price = li.findAll('span', {'class': 'price'})[0].contents[-1].strip()
31
                price = removePriceFormatting(li.findAll('span', {'class': 'price'})[0].contents[-1].strip())
31
            
32
            
32
            url = li.findAll('a')[0]['href']
33
            url = li.findAll('a')[0]['href']
33
            
34
            
34
            try:
35
            try:
-
 
36
                phone_prices.append({
-
 
37
                        'name': str(name), 
-
 
38
                        'price': str(price),
-
 
39
                        'source': 'infibeam', 
-
 
40
                        'in_stock': 1, 
35
                phone_prices.append({'name': str(name), 'price': str(price), 'in_stock': 1, 'product_url': str(url)})
41
                        'product_url': str(url)
-
 
42
                    })
36
                
43
                
37
            except UnicodeEncodeError as e:
44
            except UnicodeEncodeError as e:
38
                print 'Unicode Error', e, name
45
                print 'Unicode Error', e, name
39
                name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
46
                name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
40
                print name_ascii
47
                print name_ascii
-
 
48
                phone_prices.append({
-
 
49
                        "name": str(name_ascii), 
-
 
50
                        "price": str(price),
-
 
51
                        'source': 'infibeam', 
-
 
52
                        "in_stock": 1, 
41
                phone_prices.append({"name": str(name_ascii), "price": str(price), "in_stock": 1, "product_url": str(url)})
53
                        "product_url": str(url)
-
 
54
                    })
42
            
55
            
43
        return phone_prices
56
        return phone_prices
44
    
57
    
45
    def getNextUrl(self):
58
    def getNextUrl(self):
46
        b = self.soup.findAll('div', {'class': 'resultsSummary'})[0].findAll('b')
59
        b = self.soup.findAll('div', {'class': 'resultsSummary'})[0].findAll('b')