Advertisement
ekostadinov

Online job search duties by desired criteria

Aug 18th, 2014
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.13 KB | None | 0 0
  1. function LoginJobs($browser)
  2. {  
  3.  $browser.navigate("http://jobs.bg/login.php")
  4.  $browser.Visible = $true
  5.  Start-Sleep -Seconds 2
  6.  $doc = $browser.Document
  7.  $mails = $doc.getElementsByName("username")
  8.  foreach($m in $mails)
  9.  {
  10.   $m.value = "user.user@usermail.com"
  11.  }
  12.  $pass = $doc.getElementsByName("password")
  13.  foreach($p in $pass)
  14.  {
  15.   $p.value = "userPass"
  16.  }
  17.  $nobr = $doc.getElementsByTagName("nobr")
  18.  foreach($b in $nobr)
  19.  {
  20.   if($b.innerText -eq 'Вход')
  21.   {
  22.    $b.click()
  23.   }
  24.  }
  25. }
  26. function SearchJobs($browser)
  27. {
  28.     #$browser.fullscreen = $true
  29.     #navigate to search jobs
  30.     $doc = $browser.Document
  31.     $links = $doc.getElementsByTagName("a")
  32.     foreach($a in $links)
  33.     {
  34.       if($a.innerText -eq 'Начало')
  35.       {
  36.        $a.click()
  37.       }
  38.     }
  39.     #select required region
  40.     $region = $doc.getElementsByName('region')
  41.     if($region.item(0).item(23).innerText -match 'Sofia')
  42.     {
  43.        $region.item(0).item(23).selected = $true
  44.        $region.item(0).fireEvent('onchange')
  45.     }
  46.     #select required categories
  47.     $categories = $doc.getElementsByName('l_category[]')
  48.     if($categories.item(0).item(5).innerText -match 'IT')
  49.     {
  50.        $categories.item(0).item(5).selected = $true
  51.        $categories.item(0).fireEvent('onchange')
  52.        Start-Sleep -Seconds 0.5
  53.     }
  54.     if( $categories.item(0).item(3).innerText -match 'Software')
  55.     {
  56.        $categories.item(0).item(3).selected = $true
  57.        $categories.item(0).fireEvent('onchange')
  58.        Start-Sleep -Seconds 0.5
  59.     }
  60.     if( $categories.item(0).item(6).innerText -match 'QA')
  61.     {
  62.        $categories.item(0).item(6).selected = $true
  63.        $categories.item(0).fireEvent('onchange')
  64.        Start-Sleep -Seconds 0.5
  65.     }
  66.      if( $categories.item(0).item(9).innerText -match 'Quality')
  67.     {
  68.        $categories.item(0).item(9).selected = $true
  69.        $categories.item(0).fireEvent('onchange')
  70.        Start-Sleep -Seconds 0.5
  71.     }
  72.     if( $categories.item(0).item(11).innerText -match 'IT Administration')
  73.     {
  74.        $categories.item(0).item(11).selected = $true
  75.        $categories.item(0).fireEvent('onchange')
  76.        Start-Sleep -Seconds 0.5
  77.     }
  78.     if( $categories.item(0).item(17).innerText -match 'IT Quality')
  79.     {
  80.        $categories.item(0).item(17).selected = $true
  81.        $categories.item(0).fireEvent('onchange')
  82.        Start-Sleep -Seconds 0.5
  83.     }
  84.      #select  position Level
  85.     $positionLevel = $doc.getElementsByName('position_level[]')
  86.     $positionLevel.item(2).checked = $true
  87.     Start-Sleep -Seconds 0.5
  88.     #select  job Type
  89.     $jobType = $doc.getElementsByName('job_type')
  90.     $jobType.item(0).checked = $true
  91.     Start-Sleep -Seconds 0.5
  92.     #select agency FREE Type
  93.     $companyType = $doc.getElementsByName('company_type[]')
  94.     $companyType.item(0).checked = $true
  95.     Start-Sleep -Seconds 1
  96.     $companyType.item(1).checked = $true
  97.     #select job Hours FULL DAY
  98.     $jobHours = $doc.getElementsByName('job_hours')
  99.     $jobHours.item(0).checked = $true
  100.     #search btn
  101.     $searchBtn = $doc.getElementsByTagName('nobr')
  102.     if($searchBtn.item(0).innerText -match 'Търсене')
  103.     {
  104.         $searchBtn.item(0).click()
  105.     }
  106. }
  107. function CrawlJobLinks($pageLink, $callsCounter)
  108. {      
  109.     $lastie = $null
  110.     $lastie = new-object -com "InternetExplorer.Application"
  111.     $lastie.navigate($pageLink)
  112.     $lastie.visible = $true
  113.     Start-Sleep -Seconds 2
  114.     $lastiedoc = $lastie.document
  115.     #select results FROM LAST LOGIN - must not do it more than once
  116.     if($callsCounter -le 1)
  117.     {
  118.         $lastLogin = $lastiedoc.getElementsByName('last')
  119.         if($lastLogin.item(0).item(1).innertext -match 'От последното влизане')
  120.         {
  121.            $lastLogin.item(0).item(1).selected =$true
  122.            $lastLogin.item(0).fireEvent('onchange')
  123.         }
  124.         Start-Sleep -Seconds 2  
  125.     }
  126.     $jobLinks = $lastiedoc.getElementsByTagName('a') |where ClassName -match 'MainLinkBold' | select -Property href
  127.  #check if we have atleast one page with jobs
  128.     if($jobLinks -ne $null)
  129.     {  
  130.      for($i = 1; $i -le $jobLinks.Length - 1; $i++)
  131.      {            
  132.       $nextlink = ""
  133.       $nextLink =  $jobLinks[$i].href.ToString()
  134.             $br = new-object -com "InternetExplorer.Application"
  135.             $br.visible = $true
  136.             $br.fullscreen= $true
  137.             $br.navigate($nextLink)
  138.             Start-Sleep -Seconds 2          
  139.             $dc = $br.Document          
  140.             $aList = $dc.getElementsByTagName("a")          
  141.             foreach($at in $aList)
  142.             {
  143.                 #check for 'apply via linkedin' link
  144.                 #if($at.innerText -match "Кандидатствай с LinkedIn")
  145.                 #{
  146.                 #    $at.click()
  147.                 #    ApplyViaLinkedIn -browser $br
  148.                 #    break                  
  149.                 #}
  150.                 #logic for CV
  151.                 if($at.innerText -match "Кандидатствай по тази обява")
  152.                 {                
  153.                     $at.click()
  154.                     ApplyViaCV -browser $br
  155.                 }
  156.              }
  157.              #set back to zero
  158.       $reqs = $null
  159.          $str = $null
  160.       $nextLink = $null
  161.       $job = $null
  162.             Start-Sleep -Seconds 2
  163.             $success = $dc.getElementsByTagName('b')
  164.             foreach($s in $success.item(0))
  165.             {
  166.                 if($s.innerText -match 'Вашето CV беше изпратено успешно.')
  167.                 {
  168.                     $br.Quit()
  169.                 }
  170.                 else{
  171.                     $br.Quit()
  172.                     $br.visible = $true
  173.                 }
  174.             }
  175.      }
  176.         #check if there are more than one page with jobs      
  177.         $pages = ''
  178.         $pages = $lastiedoc.getElementsByTagName('a') | where ClassName -match 'pathlink' | select
  179.         if($pages -ne $null)
  180.         {  
  181.             #recursion bottom
  182.             #divide length because keep-alive session windows affects pages number
  183.             if($pages.Length / 2 -ne $callsCounter)
  184.             {
  185.                 $callsCounter++
  186.                 $gotoNextPage = ''
  187.                 $dummyCounter = $callsCounter + 1
  188.                 $callsCounterStr = $dummyCounter.ToString()
  189.                 foreach($p in $pages)
  190.                 {
  191.                     if($p.innerText -eq $callsCounterStr)
  192.                     {
  193.                         $p.click()
  194.                         Start-Sleep -Seconds 2
  195.                         $gotoNextPage = $lastie.LocationURL.ToString()
  196.                     }
  197.                 }
  198.                 #done by recursion          
  199.                 CrawlJobLinks -pageLink $gotoNextPage -callsCounter $callsCounter
  200.             }          
  201.             else{
  202.                $ie.Quit()
  203.                $br.Quit()
  204.             }
  205.         }
  206.     }
  207. }
  208. function ApplyViaLinkedIn($browser)
  209. {
  210.     $dc = $browser.Document  
  211.     #check for education
  212.     $education = ""
  213.     Start-Sleep -Seconds 3
  214.     $education = $dc.getElementById("education_level_sid")
  215.     if($education -ne $null)
  216.     {
  217.       $bakalavur = $education.all.item(4)    
  218.       $bakalavur.selected = $true    
  219.       $education.FireEvent('onchange', 1)
  220.       Start-Sleep -Seconds 3
  221.       $in = $dc.getElementsByTagName('a') | where Id -Match 'li_ui_li_gen_' | select
  222.       $in.click()
  223.       #wait for popup
  224.       Start-Sleep -Seconds 3
  225.       $iframe = $dc.getElementsByTagName("iframe") | where Id -Match 'easyXDM_IN_Lib_li_gen_' | select
  226.       $fd = $iframe.document
  227.       $fd > 'C:\Users\User\Desktop\wtf.txt'
  228.       $signInBtn = $fd.getElementsByTagName('a') | where Class -Match 'btn-new-primary IN-signin' | select
  229.  
  230.     }
  231.                            
  232. }
  233. function ApplyViaCV($browser)
  234. {
  235.   $dc = $browser.Document
  236.   Start-Sleep -Seconds 3
  237.   #set education
  238.   $education = $dc.getElementsByName("education_level_sid")
  239.   if($education -ne $null)
  240.   {
  241.     $education.item(0).item(4).selected =  $true
  242.   }
  243.   #add cv file
  244.   $cv = $dc.getElementsByName("file1")
  245.   if($cv -ne $null)
  246.   {
  247.     foreach($f in $cv.item(0))
  248.     {
  249.         if($f.innerText -match 'CV User-EN.pdf')
  250.         {
  251.             $f.selected = $true
  252.         }
  253.     }
  254.     #$cv.FireEvent('onchange', 1)
  255.   }
  256.   #add motivation letter
  257.   $ml = $dc.getElementsByName("file2")
  258.   if($ml -ne $null)
  259.   {
  260.     foreach($f in $ml.item(0))
  261.     {
  262.         if($f.innerText -match 'User Cover letter.doc')
  263.         {
  264.             $f.selected = $true
  265.         }
  266.     }  
  267.   }
  268.   #add company msg
  269.   $msgStr = "Dear ... Team,
  270.  
  271. I consider myself to be the right person and I would like to apply for the current position if given opportunity.
  272.  
  273. Best regards,
  274. User User."
  275.   $msgSubject = $dc.getElementsByName("subject")
  276.   if($msgSubject -ne $null)
  277.   {
  278.     if($msgSubject.item(0).value -eq $null)
  279.     {
  280.         $msgSubject.item(0).value = "Dear .... Team"      
  281.     }
  282.     $msgArea = $dc.getElementsByName("comment")
  283.     $msgArea.item(0).value = $msgStr
  284.   }
  285.   #click Apply
  286.   $applyBtn = $dc.getElementsByTagName('nobr')
  287.   $applyBtn.item(0).click()
  288. }
  289. #keep the session 'alive'
  290. $ie = new-object -com "InternetExplorer.Application"
  291. LoginJobs -browser $ie
  292. $jobsURL = 'http://www.jobs.bg/'
  293. #navigate to search new jobs with same predefined search criteria FROM last user login
  294. SearchJobs -browser $ie
  295. Start-Sleep -Seconds 1
  296. #counter used for the recursion bottom
  297. $callsCounter = 0
  298. CrawlJobLinks -pageLink $ie.LocationURL.ToString() -callsCounter $callsCounter
  299. $ie.quit()
  300. #
  301. #linkedin support
  302. #
  303. $inbrowser = New-Object -com "InternetExplorer.Application"
  304.  
  305. $inbrowser.Visible = $true
  306.  
  307. $inbrowser.Navigate('https://www.linkedin.com/uas/connect/user-signin?session_redirect=http%3A%2F%2Fwww%2Elinkedin%2Ecom%2Fcws%2Flogin-popup')
  308.  
  309. $indoc = $inbrowser.Document
  310.  
  311. $inMail = $indoc.getElementById('session_key-connectLoginForm')
  312.  
  313. $inMail.value = 'user.user@gmail.com'
  314.  
  315. $inpass = $indoc.getElementById('session_password-connectLoginForm')
  316.  
  317. $inpass.value = 'userpass'
  318.  
  319. $inBtn = $indoc.getElementsByName('signin') | where value -EQ 'Sign In' | select -First 1
  320.  
  321. $inBtn.click()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement