| 139 |
ashish |
1 |
'''
|
|
|
2 |
Created on 11-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 scrapy_price(BaseSpider):
|
|
|
24 |
|
|
|
25 |
def __init__(self):
|
|
|
26 |
self.domain_name = "infibeam.com"
|
|
|
27 |
da = DataHelper()
|
|
|
28 |
for pitem in da.get_all_vendors():
|
|
|
29 |
self.start_urls.append(pitem.v_url.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):
|
|
|
40 |
hxs = HtmlXPathSelector(response)
|
|
|
41 |
sites = hxs.select('//p[@class="box"]')
|
|
|
42 |
items = []
|
|
|
43 |
for site in sites:
|
|
|
44 |
item = {}
|
|
|
45 |
tmp = site.select('.//a[@class="nocol"]/@name')
|
|
|
46 |
item['title'] = tmp[0].extract()
|
|
|
47 |
psite = site.select(".//a[3][@href]/@href")[0].extract()
|
|
|
48 |
item['link'] = psite
|
|
|
49 |
items.append(item)
|
|
|
50 |
str1 = "http://www.infibeam.com"
|
|
|
51 |
da = DataHelper()
|
|
|
52 |
da.set_all_crawled(False)
|
|
|
53 |
for i in items:
|
|
|
54 |
str2 = str(i['link'])
|
|
|
55 |
if str(i['link']).find("http://www.infibeam.com") == -1:
|
|
|
56 |
str2 = str1 + str2
|
|
|
57 |
print "name"
|
|
|
58 |
print i['title']
|
|
|
59 |
print "site"
|
|
|
60 |
print str2
|
|
|
61 |
da.add_new_phone(str2,i['title'],"vendor")
|
|
|
62 |
|
|
|
63 |
#lt = len(da.get_all_phones())
|
|
|
64 |
#print "length" + str(lt)
|
|
|
65 |
#for ph in da.get_all_phones():
|
|
|
66 |
# print ph
|
|
|
67 |
|
|
|
68 |
f = open('/home/gaurav/twopassscrapy/pricelinks.txt', 'w')
|
|
|
69 |
for i in items:
|
|
|
70 |
f.write(i['title'])
|
|
|
71 |
f.write("\n")
|
|
|
72 |
f.write(i['link'])
|
|
|
73 |
f.write("\n")
|
|
|
74 |
f.close()
|
|
|
75 |
|
|
|
76 |
SPIDER = scrapy_price()
|