Created
July 17, 2017 08:12
-
-
Save forresty/ab1e8e59e523fd78b87844d9d032b2bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "nokogiri" | |
require "open-uri" | |
doc = Nokogiri::HTML(open("http://www.letscookfrench.com/recipes/find-recipe.aspx?s=strawberry&type=all")) | |
# puts doc.class | |
# CSS selector => | |
# a => elements named a | |
# #logo => element with attr id=logo | |
# .staff => elements with attr class=staff | |
p doc.at_css('#ctl00_cphMainContent_m_ctrlSearchEngine_m_ctrlSearchListDisplay_m_ctrlSearchPagination_m_linkNextPage') | |
doc.search('.m_contenu_resultat').each do |recipe_element| | |
title = recipe_element.at_css('.m_titre_resultat a')['title'] | |
link = recipe_element.at_css('.m_titre_resultat a')['href'] | |
prep_time = recipe_element.at_css('.m_prep_time').next.text.strip | |
# p recipe_element.at_css('.m_cooking_time').next | |
cooking_time = recipe_element.at_css('.m_cooking_time') && | |
recipe_element.at_css('.m_cooking_time').next.text.strip | |
result = { | |
title: title, | |
link: 'http://www.letscookfrench.com' + link, | |
prep_time: prep_time, | |
cooking_time: cooking_time | |
} | |
# p result | |
end | |
# should_present && possible_dangerous_expression | |
# doc.search('a').each do |a| | |
# # a is an Element, it has attributes | |
# # access attributes with [] | |
# puts a['href'] | |
# end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment