learn-co-curriculum / oo-student-scraper

Other
2 stars 316 forks source link

Issue with the Student-Scrapper final lab #45

Closed rnhutsko closed 8 years ago

rnhutsko commented 8 years ago

So I had an issue yesterday on this lab and was asked to raise an issue for the bug to be addressed. The issue is that when scrapping the index page for the students profile page url we grab a shortened version of the url. This shortened version will pass the rspec tests but will not populate students into the array for eventual output at runtime. I will post code next to make this more clear....

class Scraper

  def self.scrape_index_page(index_url)
    #doc = Nokogiri::HTML(open(index_url))
    doc = Nokogiri::HTML(open(index_url+'/fixtures/student-site/index.html'))
    student_array =[]
    doc.css(".student-card").each do |card|  
      student_hash = {}
      student_hash =  {
      :name => card.css(".student-name").text,
      :location => card.css(".student-location").text,
      :profile_url => "http://127.0.0.1:4000/fixtures/student-site/" + card.css("a").attr('href').text
      }
      student_array << student_hash
    end
    student_array #do not move or delete
  end

  def self.scrape_profile_page(profile_url)

    doc = Nokogiri::HTML(open(profile_url))
    profile_page_hash = {}          
    doc.css(".social-icon-container a").each do |link|        
      if link.attr('href').include?("twitter")
        profile_page_hash[:twitter] = link.attr('href')
      elsif link.attr('href').include?("linkedin")
        profile_page_hash[:linkedin] = link.attr('href')
      elsif link.attr('href').include?("github")
        profile_page_hash[:github] = link.attr('href') 
      else
       profile_page_hash[:blog] = link.attr('href')
    end
  end        
  profile_page_hash[:profile_quote] = doc.css("div.vitals-text-container div.profile-quote").text
  profile_page_hash[:bio] = doc.css("div.description-holder p").text
  profile_page_hash #do not move or delete
  end

end

The code just submitted will work at runtime but will fail the test. This is because line 12 reads as follows...

:profile_url => "http://127.0.0.1:4000/fixtures/student-site/" + card.css("a").attr('href').text

To pass the test the line has to be shortened to...

:profile_url => "http://127.0.0.1:4000/" + card.css("a").attr('href').text

It seems the path is not correct in the spec file.

aturkewi commented 8 years ago

Thanks for raising this issue! I've updated the lab so it just pulls the local HTML file without running up a server.

Please keep raising issues if you see anything else, and thanks for helping us make Learn better!