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 LetsBuyScraper(BaseScraper):
10
class LetsBuyScraper(BaseScraper):
10
    
11
    
11
    def __init__(self):
12
    def __init__(self):
12
        BaseScraper.__init__(self)
13
        BaseScraper.__init__(self)
Line 24... Line 25...
24
        phone_prices = []
25
        phone_prices = []
25
 
26
 
26
        for div in self.soup.findAll('div', {'class': "detailbox"}):
27
        for div in self.soup.findAll('div', {'class': "detailbox"}):
27
            name_tag = div('h2')[0]('a')[0]
28
            name_tag = div('h2')[0]('a')[0]
28
            name = name_tag.string.strip()
29
            name = name_tag.string.strip()
29
            price = div.findAll('span', {'class': "text12_stb"})[0].string.strip()
30
            price = removePriceFormatting(div.findAll('span', {'class': "text12_stb"})[0].string.strip())
30
            url = str(name_tag['href'])
31
            url = str(name_tag['href'])
31
            try:
32
            try:
-
 
33
                phone_prices.append({
-
 
34
                        "name": str(name), 
-
 
35
                        "price": str(price),
-
 
36
                        'source': 'letsbuy', 
-
 
37
                        "in_stock": 1, 
32
                phone_prices.append({"name": str(name), "price": str(price), "in_stock": 1, "product_url": str(url)})
38
                        "product_url": str(url)
-
 
39
                    })
33
            except UnicodeEncodeError as e:
40
            except UnicodeEncodeError as e:
34
                print 'Unicode Error', e, name
41
                print 'Unicode Error', e, name
35
                name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
42
                name_ascii = "".join([char if ord(char) < 128 else " " for char in name])
36
                print name_ascii
43
                print name_ascii
-
 
44
                phone_prices.append({
-
 
45
                        "name": str(name_ascii), 
-
 
46
                        "price": str(price),
-
 
47
                        'source': 'letsbuy', 
-
 
48
                        "in_stock": 1, 
37
                phone_prices.append({"name": str(name_ascii), "price": str(price), "in_stock": 1, "product_url": str(url)})
49
                        "product_url": str(url)
-
 
50
                    })
38
            
51
            
39
        return phone_prices
52
        return phone_prices
40
    
53
    
41
    def getNextUrl(self):
54
    def getNextUrl(self):
42
        next_url = None
55
        next_url = None