Subversion Repositories SmartDukaan

Rev

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

Rev 12190 Rev 12191
Line 1... Line 1...
1
import urllib2
1
import urllib2
2
from BeautifulSoup import BeautifulSoup
2
from BeautifulSoup import BeautifulSoup
3
import re
3
import re
4
from sys import exit
4
from sys import exit
5
from datetime import datetime
-
 
6
 
5
 
7
class FlipkartScraper:
6
class FlipkartScraper:
8
    def __init__(self):
7
    def __init__(self):
9
        self.count_trials = 0
8
        self.count_trials = 0
10
    
9
    
Line 13... Line 12...
13
        request.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1')
12
        request.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1')
14
        opener = urllib2.build_opener()
13
        opener = urllib2.build_opener()
15
        response_data = ""
14
        response_data = ""
16
        try:
15
        try:
17
            response_data = opener.open(request).read()
16
            response_data = opener.open(request).read()
18
            print "Response fetched ",datetime.now()
-
 
19
            
17
            
20
        except urllib2.HTTPError as e:
18
        except urllib2.HTTPError as e:
21
            print 'ERROR: ', e
19
            print 'ERROR: ', e
22
            print 'Retrying'
20
            print 'Retrying'
23
            self.count_trials += 1
21
            self.count_trials += 1
Line 110... Line 108...
110
                if not temp.has_key('shippingTime'):
108
                if not temp.has_key('shippingTime'):
111
                    print "Populating shipping time from metrics"
109
                    print "Populating shipping time from metrics"
112
                    temp['shippingTime'] = dataMetric[3]
110
                    temp['shippingTime'] = dataMetric[3]
113
                temp['sellerScore'] = int(dataMetric[4])
111
                temp['sellerScore'] = int(dataMetric[4])
114
                info.append(temp)
112
                info.append(temp)
115
        print "Returning response ",datetime.now()
-
 
116
        return info
113
        return info
117
 
114
 
118
if __name__ == '__main__':
115
if __name__ == '__main__':
119
    print datetime.now()
-
 
120
    scraper = FlipkartScraper()
116
    scraper = FlipkartScraper()
121
    scraper.read('http://www.flipkart.com/ps/ACCDSN84XXH5P9WG')
117
    scraper.read('http://www.flipkart.com/ps/ACCDSN84XXH5P9WG')
122
    print scraper.createData()
118
    print scraper.createData()
123
    print datetime.now()
-
 
124
    
119
    
125
120