| 187 |
ashish |
1 |
'''
|
|
|
2 |
Created on 27-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 |
|
|
|
19 |
from datastore import DataAccessor
|
|
|
20 |
from datastore.DataAccessor import DataHelper
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
class naaptol_spider(BaseSpider):
|
|
|
24 |
|
|
|
25 |
def __init__(self):
|
|
|
26 |
self.domain_name = "naaptolsites"
|
|
|
27 |
str1 = "http://www.naaptol.com/sitemap.xml"
|
|
|
28 |
self.start_urls.append(str1)
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
def start_requests(self):
|
|
|
32 |
da = DataHelper()
|
|
|
33 |
da.add_supplier(self.domain_name, "www.naaptol.com")
|
|
|
34 |
listreq = []
|
|
|
35 |
for url1 in self.start_urls:
|
|
|
36 |
request = Request(url = str(url1), callback=self.parse)
|
|
|
37 |
request.headers.setdefault("Referer", "http://www.naaptol.com/sitemap.xml")
|
|
|
38 |
listreq.append(request)
|
|
|
39 |
return listreq
|
|
|
40 |
|
|
|
41 |
def parse(self, response):
|
|
|
42 |
da = DataHelper()
|
|
|
43 |
hxs = HtmlXPathSelector(response)
|
|
|
44 |
phone_urls = hxs.select('//url/loc/text()')
|
|
|
45 |
for i in phone_urls:
|
|
|
46 |
site = i.extract()
|
|
|
47 |
pos1 = pos2 = pos3 = 0
|
|
|
48 |
temp =""
|
|
|
49 |
pos1 = site.rfind('/')
|
|
|
50 |
if pos1 != -1:
|
|
|
51 |
pos2 = site.rfind('/',0,pos1-1)
|
|
|
52 |
if pos2 != -1:
|
|
|
53 |
pos3 = site.rfind('/',0,pos2-1)
|
|
|
54 |
if pos3 > 0:
|
|
|
55 |
temp = site[pos3+1:pos1]
|
|
|
56 |
if temp == "mobile_phones/pdas_and_smartphones" or temp == "mobile_phones/gsm_handsets" or temp == "mobile_phones/cdma_handsets":
|
|
|
57 |
da.add_naaptolurl(site)
|
|
|
58 |
#print str(ct) + " " + site
|
|
|
59 |
#print "\n"
|
|
|
60 |
#ct = ct +1
|
|
|
61 |
|
|
|
62 |
SPIDER = naaptol_spider()
|