| 221 |
ashish |
1 |
'''
|
|
|
2 |
Created on 06-Jun-2010
|
|
|
3 |
|
|
|
4 |
@author: gaurav
|
|
|
5 |
'''
|
|
|
6 |
|
|
|
7 |
from scrapy.spider import BaseSpider
|
|
|
8 |
from scrapy.selector import HtmlXPathSelector
|
|
|
9 |
from scrapy.http import Request
|
|
|
10 |
|
|
|
11 |
from demo.items import DemoItem
|
|
|
12 |
from scrapy.contrib.spidermiddleware import referer
|
|
|
13 |
from scrapy.http.headers import Headers
|
|
|
14 |
from scrapy.http.request.form import FormRequest
|
|
|
15 |
from scrapy.log import msg
|
|
|
16 |
from scrapy.http.response import Response
|
|
|
17 |
|
|
|
18 |
from datastore.DataAccessor import *
|
|
|
19 |
from datastore.DataCodeAccessor import *
|
|
|
20 |
from html2text import *
|
|
|
21 |
from babel.messages.pofile import unescape
|
|
|
22 |
import urllib
|
|
|
23 |
|
|
|
24 |
class babuchak2(BaseSpider):
|
|
|
25 |
|
|
|
26 |
def __init__(self):
|
|
|
27 |
initialize_table()
|
|
|
28 |
#BABUCHAK_DOMAINNAME1 = "babuchak1"
|
|
|
29 |
BABUCHAK_DOMAINNAME1 = get_code_word("BABUCHAK_DOMAINNAME1")
|
|
|
30 |
self.domain_name = BABUCHAK_DOMAINNAME1
|
|
|
31 |
#BABUCHAK_VAR1 = "&postPage="
|
|
|
32 |
BABUCHAK_VAR1 = get_code_word("BABUCHAK_VAR1")
|
|
|
33 |
da = DataHelper()
|
|
|
34 |
for item in da.get_allbabuchakurls():
|
|
|
35 |
ct = item.no_pages
|
|
|
36 |
while ct>0:
|
|
|
37 |
url = item.url + BABUCHAK_VAR1
|
|
|
38 |
url = url + str(ct)
|
|
|
39 |
self.start_urls.append(url)
|
|
|
40 |
ct = ct -1
|
|
|
41 |
session.close()
|
|
|
42 |
|
|
|
43 |
def start_requests(self):
|
|
|
44 |
listreq = []
|
|
|
45 |
#for each request a referer has to be set
|
|
|
46 |
#BABUCHAK_REFERER = "www.google.com/search"
|
|
|
47 |
BABUCHAK_REFERER = get_code_word("BABUCHAK_REFERER")
|
|
|
48 |
for url1 in self.start_urls:
|
|
|
49 |
request = Request(url = str(url1), callback=self.parse)
|
|
|
50 |
request.headers.setdefault("Referer", BABUCHAK_REFERER)
|
|
|
51 |
listreq.append(request)
|
|
|
52 |
return listreq
|
|
|
53 |
|
|
|
54 |
def parse(self, response):
|
|
|
55 |
#url1 needed to get complete urls
|
|
|
56 |
da = DataHelper()
|
|
|
57 |
#BABUCHAK_URL2 = "http://www.shopping.babuchak.com/visitourstores.php"
|
|
|
58 |
BABUCHAK_URL2 = get_code_word("BABUCHAK_URL2")
|
|
|
59 |
hxs = HtmlXPathSelector(response)
|
|
|
60 |
#BABUCHAK_XPATH4 = '//td[@class="mod-item-body-title"]/a/@href'
|
|
|
61 |
BABUCHAK_XPATH4 = get_code_word("BABUCHAK_XPATH4")
|
|
|
62 |
|
|
|
63 |
info = hxs.select(BABUCHAK_XPATH4)
|
|
|
64 |
for i in info:
|
|
|
65 |
url = i.extract()
|
|
|
66 |
url = url.strip()
|
|
|
67 |
url = BABUCHAK_URL2 + url
|
|
|
68 |
da.add_babuchakphoneurl(url)
|
|
|
69 |
session.remove()
|
|
|
70 |
|
|
|
71 |
SPIDER = babuchak2()
|