from scrapy spider import Spider from scrapy selector import Selector

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
from scrapy.spider import Spider
from scrapy.selector import Selector
from scrapy.http import Request
from rhw.items import JobItem
import time
import re
class excelhr(Spider):
name = "excelhr"
#driver= webdriver.PhantomJS('phantomjs',service_args=['--ssl-protocol=tlsv1'])
lang = ''
rowFrom = ''
location = ''
title = ''
city = ''
description = ''
category = ''
job_id = ''
driver = None
start_urls = [
'http://www.excelhr.com/english/JobSearchGlobal/JobSearchGlobal.asp'
]
#url_app = 'http://recruitingsite.com/csbsites/atlantic/workopolis/'
#def __init__(self, *a, **kw):
#self.driver= webdriver.PhantomJS('phantomjs',service_args=['--ssl-protocol=tlsv1'])
def parse(self, response):
hxs = Selector(response)
jobs = hxs.xpath('//table//table//tr[position()>2]')
html = Selector(response)
items = []
ind = 0
for job in jobs:
ind += 1
if ind > 2:
print ind
item = JobItem()
#item['title'] = html.xpath('.//td[1]').extract()[0]
#if job.xpath('.//td[1]').extract()[0].strip() != '':
#url = job.xpath('@href')
item['apply_url'] = job.xpath('.//td[1]/strong/a/@href').extract()[0]
item['position_type'] = job.xpath('string(.//td[3])').extract()[0].strip()
#print item['apply_url']
location = job.xpath("string(.//td[4])").extract()[0].strip()
#print item['location'
location = location.split(',')
if '-' in location[0]:
city = location[0].split('-')
item['city'] = city[0]
else:
item['city'] = location[0]
if len(location) > 1:
item['state'] = location[1]
#item['language'] = 'en'
d_url = item['apply_url']
request = Request(d_url, callback=self.parse_details)
request.meta['item'] = item
items.append(request)
for item in items:
yield item
#driver.close()
def parse_details(self,response):
#tr = Selector(text=driver.find_element_by_xpath('//body').get_attribute('innerHTML'))
html = Selector(response)
item = response.meta['item']
item['title'] = html.xpath("string(.//span[contains(@id,'lblPositionTitle_lblLabel')])").extract()[0].strip()
#print item['title']
item['job_id'] = html.xpath("string(.//span[contains(@id,'dnn_ctr729_ViewSNADViewer_txtOpportunityNumber_lblLabel')])").extract()[0].strip()
#item['description'] = html.xpath("string(.//span[contains(@id,'dnn_ctr729_ViewSNADViewer_lblContent_lblLabel')])").extract()[0].strip()
item['description'] = ''.join(html.xpath(".//span[contains(@id,'dnn_ctr729_ViewSNADViewer_lblContent_lblLabel')]/node()").extract())
p = item['description']
p = p.replace('Apply Now',' ');
item['description'] = p
l = item['description']
l = l.replace('Refer to a Friend',' ');
item['description'] = l
#print item['description']
return item