Subversion Repositories SmartDukaan

Rev

Rev 154 | Rev 240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
154 ashish 1
'''
2
Created on 14-May-2010
3
 
4
@author: gaurav
5
'''
6
 
7
 
8
from scrapy.spider import BaseSpider
9
from scrapy.selector import HtmlXPathSelector
10
from scrapy.http import Request
11
 
12
from demo.items import DemoItem
13
from scrapy.contrib.spidermiddleware import referer
14
from scrapy.http.headers import Headers
15
from scrapy.http.request.form import FormRequest
16
from scrapy.log import msg
17
from scrapy.http.response import Response
18
#from datastore.DataAccessor import add_new_phone
19
 
20
from datastore import DataAccessor
21
from datastore.DataAccessor import DataHelper
22
 
23
class univercell_price(BaseSpider):
24
 
25
    def __init__(self):
26
       self.domain_name = "univercellphones"
27
       da = DataHelper()
28
       for pitem in da.get_all_univervendors():
29
            self.start_urls.append(pitem.v_site.strip())
30
 
31
    def start_requests(self):
32
        listreq = []
33
        for url1 in self.start_urls:
34
            request = Request(url = url1, callback=self.parse)
35
            request.headers.setdefault("Referer", "www.google.com/search")
36
            listreq.append(request)
37
        return listreq
38
 
39
    def parse(self, response):
170 ashish 40
        da = DataHelper()
154 ashish 41
        vatplustax = 0
42
        hxs = HtmlXPathSelector(response)
43
        #sites = hxs.select('//div[@id="productsDiv"]/table/tbody/tr[2]/td/div/table/tbody/tr/td/table/tbody')
44
        #sites = hxs.select('//div[@id="productsDiv"]/table/tr[2]//tr')
45
        sites = hxs.select('//td[@class="gray-border"]')
46
        items = []
47
        for site in sites:
48
            item = {}
49
            #tmp = site.select('.//tr[2]/td/a/text()')
50
            item['title'] = site.select('.//tr[2]/td/a/text()')[0].extract()
51
            #psite = site.select(".//a[3][@href]/@href")[0].extract()
52
            item['price'] =site.select('.//tr[3]/th/label/text()')[0].extract()
53
            items.append(item)
170 ashish 54
        da = DataHelper()
55
 
154 ashish 56
        for i in items:
57
            str1 = str(i['title']).strip() 
58
            print str1
59
            amnt = i['price'].replace(",","")
60
            amnt = amnt.replace("Rs", "")
61
            amnt = amnt.replace("/", "")
62
            amnt = amnt.replace("-", "")
170 ashish 63
            amnt = amnt.strip() 
64
            vatplustax = 4*int(amnt)/100
154 ashish 65
            pr = int(amnt) + vatplustax 
66
            #print pr
67
            da.add_new_univerphone(str1,amnt,pr) 
68
 
69
        #lt = len(da.get_all_phones())  
70
        #print "length" + str(lt)
71
        #for ph in da.get_all_phones():
72
         #   print ph
73
 
74
        #f = open('/home/gaurav/twopassscrapy/pricelinks.txt', 'w')
75
        #for i in items:
76
            #f.write(i['title'])
77
            #f.write("\n")
78
            #f.write(i['link'])
79
            #f.write("\n")
80
        #f.close()    
81
 
82
SPIDER = univercell_price()
83