recipe_scraper 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/recipe_scraper.rb +26 -26
- data/lib/recipe_scraper/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e025c453bfd951c2b67abaf3d27a269af4d6dd00
|
4
|
+
data.tar.gz: f32ea1856cdc9caea8caed07153d76450dc94ca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2ab974e447358d9f2f90476caea4f3cee4236c17a5dceef9e3a470ad89653c121297b725fe646f71a7dc3bbc54750a36fe90dd076952d52b4fbf704158aff4
|
7
|
+
data.tar.gz: 2aaff08dbb6c1a794d4e0d9e9ff009832802dca967d104f1b786d42e5ed90e0f6840ecf5d7071e743d8434b14989a10b7340d0069fc8923bb18e50926e250280
|
data/lib/recipe_scraper.rb
CHANGED
@@ -18,7 +18,7 @@ module RecipeScraper
|
|
18
18
|
CUISINEAZ_HOST = {desktop: 'http://www.cuisineaz.com/'}
|
19
19
|
|
20
20
|
|
21
|
-
|
21
|
+
|
22
22
|
# Instanciate a Recipe object with data crawled from an url
|
23
23
|
#
|
24
24
|
# @param url [String] representing an url from Marmiton or 750g website
|
@@ -34,7 +34,7 @@ module RecipeScraper
|
|
34
34
|
fetch_from_cuisineaz url
|
35
35
|
|
36
36
|
else
|
37
|
-
raise ArgumentError, "Instantiation cancelled (Host not supported)."
|
37
|
+
raise ArgumentError, "Instantiation cancelled (Host not supported)."
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -68,7 +68,7 @@ module RecipeScraper
|
|
68
68
|
# @param text [String] a text to sanitize
|
69
69
|
# @return [String] as text corrected formated
|
70
70
|
def sanitize text
|
71
|
-
[' ', '\r\n', "\r\n", "\n", "\r"].each { |text_to_remove|
|
71
|
+
[' ', '\r\n', "\r\n", "\n", "\r", "\t", / ^/, / $+/, /^ /, /^ /].each { |text_to_remove|
|
72
72
|
text.gsub!(text_to_remove,'')
|
73
73
|
}
|
74
74
|
return text
|
@@ -111,29 +111,30 @@ module RecipeScraper
|
|
111
111
|
url.gsub! MARMITON_HOST[:mobile], MARMITON_HOST[:desktop]
|
112
112
|
|
113
113
|
page = Nokogiri::HTML(open(url).read)
|
114
|
-
@title = page.css('h1
|
114
|
+
@title = page.css('h1').text
|
115
115
|
|
116
116
|
|
117
117
|
# get times
|
118
|
-
@preptime = page.css('
|
119
|
-
@cooktime = page.css('
|
118
|
+
@preptime = page.css('div.recipe-infos__timmings__preparation > span.recipe-infos__timmings__value').text.to_i
|
119
|
+
@cooktime = page.css('div.recipe-infos__timmings__cooking > span.recipe-infos__timmings__value').text.to_i
|
120
120
|
|
121
121
|
# get ingredients
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
@ingredients = []
|
123
|
+
ingredients_text = page.css('ul.recipe-ingredients__list li.recipe-ingredients__list__item').each do |ingredient_tag|
|
124
|
+
@ingredients << sanitize(ingredient_tag.text)
|
125
|
+
end
|
125
126
|
|
126
127
|
# get steps
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
@steps = []
|
129
|
+
steps_text = page.css('ol.recipe-preparation__list').each do |step_tag|
|
130
|
+
@steps << sanitize(step_tag.text)
|
131
|
+
end
|
130
132
|
|
131
133
|
# get image
|
132
|
-
@image = page.css('
|
133
|
-
|
134
|
+
@image = page.css('#af-diapo-desktop-0_img').attr('src').to_s rescue NoMethodError
|
134
135
|
|
135
136
|
else
|
136
|
-
raise ArgumentError, "Instantiation cancelled (ulr not from #{MARMITON_HOST})."
|
137
|
+
raise ArgumentError, "Instantiation cancelled (ulr not from #{MARMITON_HOST})."
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
@@ -147,8 +148,8 @@ module RecipeScraper
|
|
147
148
|
@title = page.css('h1.c-article__title').text
|
148
149
|
|
149
150
|
# get times
|
150
|
-
@preptime = page.css('ul.c-recipe-summary li
|
151
|
-
@cooktime = page.css('ul.c-recipe-summary li
|
151
|
+
@preptime = sanitize(page.css('ul.c-recipe-summary > li.c-recipe-summary__rating[title="Temps de préparation"]').text).to_i
|
152
|
+
@cooktime = sanitize(page.css('ul.c-recipe-summary > li.c-recipe-summary__rating[title="Temps de cuisson"]').text).to_i
|
152
153
|
|
153
154
|
@steps = []
|
154
155
|
css_step = "div[itemprop=recipeInstructions] p"
|
@@ -166,9 +167,9 @@ module RecipeScraper
|
|
166
167
|
@image = page.css(css_image).attr('src').to_s
|
167
168
|
rescue NoMethodError => e
|
168
169
|
end
|
169
|
-
|
170
|
+
|
170
171
|
else
|
171
|
-
raise ArgumentError, "Instantiation cancelled (ulr not from #{G750_HOST})."
|
172
|
+
raise ArgumentError, "Instantiation cancelled (ulr not from #{G750_HOST})."
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
@@ -185,27 +186,26 @@ module RecipeScraper
|
|
185
186
|
@preptime = page.css('#ctl00_ContentPlaceHolder_LblRecetteTempsPrepa').text.to_i
|
186
187
|
@cooktime = page.css('#ctl00_ContentPlaceHolder_LblRecetteTempsCuisson').text.to_i
|
187
188
|
|
188
|
-
|
189
189
|
@steps = []
|
190
|
-
page.css("#preparation
|
190
|
+
page.css("#preparation p").each { |step_node|
|
191
191
|
@steps << sanitize(step_node.text)
|
192
192
|
}
|
193
193
|
|
194
194
|
@ingredients = []
|
195
|
-
page.css("
|
195
|
+
page.css("section.recipe_ingredients li").each { |ing_node|
|
196
196
|
@ingredients << sanitize(ing_node.text)
|
197
197
|
}
|
198
198
|
|
199
199
|
begin
|
200
|
-
@image = page.css('#
|
200
|
+
@image = page.css('#ctl00_ContentPlaceHolder_recipeImgLarge').attr('src').to_s
|
201
201
|
rescue NoMethodError => e
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
else
|
205
|
-
raise ArgumentError, "Instantiation cancelled (ulr not from #{G750_HOST})."
|
205
|
+
raise ArgumentError, "Instantiation cancelled (ulr not from #{G750_HOST})."
|
206
206
|
end
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
end
|
210
210
|
|
211
211
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recipe_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- madeindjs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.6.11
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A web scrawler to get a Marmiton's, cuisineaz or 750g recipe
|