Class: HotjobsSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo/hotjobs.rb

Overview

Scrap the Yahoo Hotjobs website

hotjobs.yahoo.com

Constant Summary collapse

DEBUG =

Constants

false
TITLE_CELL =
0
COMPANY_CELL =
1
LOCATION_CELL =
2
DATE_CELL =
3
CELL_COUNT =
4
"http://hotjobs.yahoo.com"

Class Method Summary collapse

Class Method Details

.get_listings(url) ⇒ Object

Retrieve the job listings

Parameters:

  • url (String, #read)

    the url used to query the data

  • an (JobListings)

    array of job listings



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/yahoo/hotjobs.rb', line 82

def self.get_listings(url)

     # Read the data from the url
     response = open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}",
                    "From" => "[email protected]",
                    "Referer" => "http://hotjobs.yahoo.com/").read

     # Parse the listings from the query
     parse_listings(response)

end

.parse_listings(query) ⇒ Object

Parse the provided query data

Parameters:

  • query (String, #read)

    the html web page data



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
# File 'lib/yahoo/hotjobs.rb', line 24

def self.parse_listings(query)

     # Create the listings
     listings = Array.new

     # Filter the data with Hpricot
     doc = Hpricot(query)

     # Get the table
     table = (doc/"//table[@id=results]")
     
     # Iterate through each row
     rows = (table/"tr")
     
     # Retrieve the table rows that contain the job listings
     rows.each { |row|
     
          # Get the individual cells
          cells = (row/"td")
     
          # If this is a job listing
          if cells.size == CELL_COUNT

               # Get the fields
               name = (cells[TITLE_CELL]/"a").inner_html
               link = HOTJOBS_LINK + (cells[TITLE_CELL]/"a").attr("href")
               company = (cells[COMPANY_CELL]/"a").inner_html
               company_link = HOTJOBS_LINK + (cells[COMPANY_CELL]/"a").attr("href")
               location = get_location(cells[LOCATION_CELL])
               date, repost = get_dates(cells[DATE_CELL])

               if DEBUG
                    puts "Row: count #{cells.size}"
                    puts "Name: #{name}"
                    puts "Link: #{link}"
                    puts "Company: #{company}"
                    puts "Company Link: #{company_link}"
                    puts "Location: #{location}"
                    puts "Date: #{date}"
                    puts "Repost: #{date}"
               end

               # Create the job listing
               listings << JobListing.new(name, link, company, company_link, location, date, repost)

          end

     }

     # Return the listings
     return listings

end

.query(location, keywords, days_back, num_entries) ⇒ Object

Query yahoo for html code for the query

Parameters:

  • location (String, #read)

    the location to search

  • keywords (String, #read)

    keywords to use for the search

  • days_back (String, #read)

    how long ago to search

  • num_entries (String, #read)

    the number of entries to request



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/yahoo/hotjobs.rb', line 100

def self.query(location, keywords, days_back, num_entries)

     url = "http://hotjobs.yahoo.com/job-search?" +
          "src=advsearch&pageOp=search&ts=1259353986&" +
          "kw_search_type=kwany&kw=#{keywords}&kw_none=&" +
          "locations=#{location}&country=&locations=&locations=&" +
          "industry=&industry=&industry=&" +
          "updated_since=month&" +
          "exp_level=&experience_level=&" +
          "education=&salary[min]=&salary[type]=yearly&" +
          "commitment=FT&commitment=PT&jobtype=PERM&jobtype=CONT&" +
          "travel_amount=&company=&" +
          "source=&email_format=html&email_frequency=1&email_enabled=0&search_jobs=Search+Jobs"

     # Read the data from the url
     open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}",
          "From" => "[email protected]",
          "Referer" => "http://hotjobs.yahoo.com/").read
end