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
from scrapy.spider import Spider
from scrapy.selector import Selector
from scrapy.http import Request
from scrapy_webdriver.http import WebdriverRequest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from diversity.items import JobItem
from scrapy import log
import time
import re
class eytaleo(Spider):
name = "eytaleo"
driver= None
driver= webdriver.PhantomJS('phantomjs')
start_urls = [
'https://ey.taleo.net/careersection/gexp01/jobsearch.ftl?lang=en&location=200000001&dropListSize=100'
]
url_app = 'https://ey.taleo.net/careersection/gexp01/jobdetail.ftl?job=jobcode'
def __init__(self, *a, **kw):
self.driver= webdriver.PhantomJS('phantomjs',service_args=['--ssl-protocol=tlsv1'])
def parse(self, response):
hxs = Selector(response)
driver = self.driver
driver.get(response.url)
time.sleep(1)
items = []
no_more_pages = False
page = 0
while True:
page += 1
print page
element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "requisitionListInterface.ID8360.row")))
time.sleep(1)
rows = driver.find_elements_by_xpath('.//table[contains(@id,"requisitionListInterface.listRequisition")]/tbody//tr[contains(@class,"ftlrow")]')
if not rows:
break
for tr in rows:
item = JobItem()
html = Selector(text=tr.get_attribute('innerHTML'))
di = html.xpath("string(.//span[contains(@id,'requisitionListInterface.reqContestNumberValue')])").extract()[0].strip()
item['apply_url'] = self.url_app.replace('jobcode',di)
item['title'] = html.xpath("string(//a[contains(@id,'requisitionListInterface.reqTitleLinkAction')])").extract()[0].strip()
print item['apply_url']
d_url = item['apply_url']
if item['title']:
items.append(item)
html = Selector(text = driver.page_source)
print html.xpath("string(//span[@class='pagerlink']/a[contains(.,'Next')])").extract()[0]
if html.xpath("string(//span[@class='pagerlink']/a[contains(.,'Next')])").extract()[0].strip() != '':
driver.find_element_by_xpath("//span[@class='pagerlink']/a[contains(.,'Next')]").click()
time.sleep(1)
else:
break
no_more_pages = True
if no_more_pages:
break
items2 = []
for it in items:
request = WebdriverRequest(it['apply_url'], callback=self.parse_details)
request.meta['item'] = it
items2.append(request)
return items2
def parse_details(self,response):
tr = Selector(response)
item = response.meta['item']
item['title'] = tr.xpath("string(.//*[contains(@id,'requisitionDescriptionInterface.reqTitleLinkAction.row1')])").extract()[0]
g = item['title'].split('-')
item['title'] = g[0]
if len(g) > 1:
item['category'] = g[1]
n = tr.xpath("string(.//*[contains(@id,'requisitionDescriptionInterface.ID1633')])").extract()[0]
n = n.split('-')
if len(n) == 3:
item['city'] = n[2]
item['state'] = n[1]
item['country'] = n[0]
if len(n) == 2:
item['state'] = n[1]
if len(n) == 1:
item['country'] = n[0]
item['description'] = ''.join(tr.xpath(".//*[contains(@id,'requisitionDescriptionInterface.ID1647.row1')]/node()").extract())
print item['description']
item['job_id'] = tr.xpath("string(.//*[contains(@id,'equisitionDescriptionInterface.reqContestNumberValue.row1')])").extract()[0]
item['min_experience'] = tr.xpath("string(.//*[contains(@id,'requisitionDescriptionInterface.ID1671.row1')])").extract()[0]
return item