1+ from selenium import webdriver
2+ from selenium .webdriver .common .keys import Keys
3+ from selenium .webdriver .support import expected_conditions as EC
4+ from selenium .webdriver .common .by import By
5+ from selenium .webdriver .support .ui import WebDriverWait
6+
7+ import urllib .request as urllib
8+ import os
9+ import time
10+ import re
11+ import logging as logger
12+
13+ from bs4 import BeautifulSoup
14+ from lxml .html import fromstring
15+
16+ class Naukri :
17+
18+ def __init__ (self ,driverPath ,id ,pwd ,url ):
19+ self ._driverPath = driverPath
20+ self ._id = id
21+ self ._pwd = pwd
22+ self ._url = url
23+
24+ def loadDriver (self ):
25+ try :
26+ if self ._driverPath is None :
27+ logger .error (" Please provide a driver path" )
28+ return
29+ if self ._url is None :
30+ logger .error (" Please provide a website url " )
31+ # open crome options pass --incognito add_argument
32+ chrome_options = webdriver .ChromeOptions ()
33+ chrome_options .add_argument ("--incognito" )
34+ self .driver = webdriver .Chrome (executable_path = self ._driverPath , options = chrome_options )
35+ # self.driver = webdriver.Firefox(executable_path = self._driverPath )
36+ self .driver .get (self ._url )
37+ except Exception as e :
38+ logger .error (str (e ))
39+ return
40+
41+ def login (self ):
42+ try :
43+ if self ._id and self ._pwd == None :
44+ logger .error (" Please provide your email and password" )
45+ return
46+ search = self .driver .find_element_by_id ('usernameField' )
47+ search .send_keys (self ._id )
48+ search = self .driver .find_element_by_id ('passwordField' )
49+ search .send_keys (self ._pwd )
50+ search .send_keys (Keys .RETURN )
51+
52+ except Exception as e :
53+ logger .error ( str (e ) )
54+ return
55+
56+ # def applyFilter(self,skill,location,exp,salary):
57+ # # Note : Selenium does not know when new page is loaded . So wait till it find element from next page
58+ # element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "qsb-location-sugg")))
59+ # print(self.driver.current_url)
60+ # search = self.driver.find_element_by_id('qsb-location-sugg')
61+ # search.click()
62+ # search.send_keys(skill)
63+ # search = self.driver.find_element_by_id('qsb-location-sugg')
64+ # search.send_keys(location)
65+ # search = self.driver.find_element_by_id('hid_expDroope-experience')
66+ # search.send_keys(exp)
67+ # search = self.driver.find_element_by_id('hid_salaryDroope-salary')
68+ # search.send_keys(salary)
69+ # search.send_keys(Keys.RETURN)
70+
71+ # search = self.driver.find_element_by_class_name('view-all right-align')
72+ # search.click()
73+
74+ # h = self.driver.find_element_by_xpath("//div[@class=view-all.right-align']//a/@href")
75+ # print(h)
76+
77+ # self.driver.find_element_by_class_name('view-all.right-align').click()
78+
79+ def applyJobs (self ):
80+ element = WebDriverWait (self .driver , 10 ).until (EC .presence_of_element_located ((By .ID , "qsb-location-sugg" )))
81+ s = self .driver .current_url
82+ s = s .replace ('homepage' , 'recommendedjobs' )
83+ self .driver .get (s )
84+ element = WebDriverWait (self .driver , 10 ).until (EC .presence_of_element_located ((By .CLASS_NAME , "jobTuple " )))
85+ print (self .driver .current_url )
86+ html = self .driver .page_source
87+ parser = fromstring (html )
88+ urls = parser .xpath ("//a[@class='tupleLink']//@href" )
89+ for u in urls :
90+ print (u )
91+ if "ambitionbox" not in u :
92+ self .driver .execute_script ("window.open('" + u + "', '_self')" )
93+ self .driver .implicitly_wait (5 )
94+
95+ element = WebDriverWait (self .driver , 5 ).until (EC .presence_of_element_located ((By .ID , "trig1" )))
96+ if element != None :
97+ print ('Applied to this : {} ' .format (u ))
98+ element .click ()
99+ else :
100+ continue
101+
102+
103+ if __name__ == '__main__' :
104+ driverPath = 'G:/Github/PythonScripts/Selenium/Driver/chromedriver.exe'
105+ # driverPath = 'G:/Github/PythonScripts/Selenium/Driver/geckodriver.exe'
106+ 107+ pwd = 'passqord^'
108+ url = 'https://www.naukri.com/nlogin/logout'
109+
110+ naukri = Naukri (driverPath ,id ,pwd ,url )
111+ naukri .loadDriver ()
112+ naukri .login ()
113+
114+ # skill = 'python'
115+ # location = 'mumbai'
116+ # exp = 1
117+ # salary = 5
118+ # naukri.applyFilter(skill,location,exp,salary)
119+
120+ naukri .applyJobs ()
121+
122+
123+
124+
125+
126+ # Input fileds : driver.clear()
127+ # id : qsb-keyskill-sugg
128+ # id : qsb-location-sugg
129+ # id : expDroope-experienceFor , hid_expDroope-experience 0 - 30 years
130+ # id : salaryDroope-salaryFor , hid_salaryDroope-salary 0 - 100 LPA
131+ # driver.find_element_by_xpath("//input[contains(@class,'view-all right-align')]").get_attribute('value')
132+ # by_xpath("//a[@class='tupleLink']//@href")
133+ # $x("//a[@class='tupleLink']")
134+
135+
136+ # print(html)
137+ # soup = BeautifulSoup(html, 'html5lib')
138+ # table = soup.findAll('a', attrs = {'class':'tupleLink'})
139+ # print(table)
140+ # for t in table:
141+ # url = t['href']
142+ # print(url)
143+ # jobLinks = self.driver.find_element_by_xpath("//a[@class='tupleLink']")
0 commit comments