diff --git a/Gemfile b/Gemfile
new file mode 100644
index 00000000..e8cf82d2
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,13 @@
+source "https://rubygems.org"
+
+ruby "3.4.6"
+
+gem 'nokogiri'
+
+group :development do
+ gem 'debug'
+end
+
+group :test do
+ gem 'rspec'
+end
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 00000000..2e177784
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,79 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ date (3.5.1)
+ debug (1.11.1)
+ irb (~> 1.10)
+ reline (>= 0.3.8)
+ diff-lcs (1.6.2)
+ erb (6.0.1)
+ io-console (0.8.2)
+ irb (1.16.0)
+ pp (>= 0.6.0)
+ rdoc (>= 4.0.0)
+ reline (>= 0.4.2)
+ nokogiri (1.19.0-aarch64-linux-gnu)
+ racc (~> 1.4)
+ nokogiri (1.19.0-aarch64-linux-musl)
+ racc (~> 1.4)
+ nokogiri (1.19.0-arm-linux-gnu)
+ racc (~> 1.4)
+ nokogiri (1.19.0-arm-linux-musl)
+ racc (~> 1.4)
+ nokogiri (1.19.0-arm64-darwin)
+ racc (~> 1.4)
+ nokogiri (1.19.0-x86_64-darwin)
+ racc (~> 1.4)
+ nokogiri (1.19.0-x86_64-linux-gnu)
+ racc (~> 1.4)
+ nokogiri (1.19.0-x86_64-linux-musl)
+ racc (~> 1.4)
+ pp (0.6.3)
+ prettyprint
+ prettyprint (0.2.0)
+ psych (5.3.1)
+ date
+ stringio
+ racc (1.8.1)
+ rdoc (7.1.0)
+ erb
+ psych (>= 4.0.0)
+ tsort
+ reline (0.6.3)
+ io-console (~> 0.5)
+ rspec (3.13.2)
+ rspec-core (~> 3.13.0)
+ rspec-expectations (~> 3.13.0)
+ rspec-mocks (~> 3.13.0)
+ rspec-core (3.13.6)
+ rspec-support (~> 3.13.0)
+ rspec-expectations (3.13.5)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-mocks (3.13.7)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.13.0)
+ rspec-support (3.13.6)
+ stringio (3.2.0)
+ tsort (0.2.0)
+
+PLATFORMS
+ aarch64-linux-gnu
+ aarch64-linux-musl
+ arm-linux-gnu
+ arm-linux-musl
+ arm64-darwin
+ x86_64-darwin
+ x86_64-linux-gnu
+ x86_64-linux-musl
+
+DEPENDENCIES
+ debug
+ nokogiri
+ rspec
+
+RUBY VERSION
+ ruby 3.4.6p54
+
+BUNDLED WITH
+ 2.6.9
diff --git a/README.md b/README.md
index 4d5a093f..05d30602 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,53 @@ Parse directly the HTML result page ([html file]) in this repository. No extra H
[html file]: https://raw.githubusercontent.com/serpapi/code-challenge/master/files/van-gogh-paintings.html
[expected array]: https://raw.githubusercontent.com/serpapi/code-challenge/master/files/expected-array.json
-Add also to your array the painting thumbnails present in the result page file (not the ones where extra requests are needed).
+Add also to your array the painting thumbnails present in the result page file (not the ones where extra requests are needed).
Test against 2 other similar result pages to make sure it works against different layouts. (Pages that contain the same kind of carrousel. Don't necessarily have to beĀ paintings.)
The suggested time for this challenge is 4 hours. But, you can take your time and work more on it if you want.
+
+## Solution
+
+I built a small carousel scraper using `Nokogiri` and regex. It finds the best Knowledge Graph carousel container by looking for `data-attrid` sections and links that include `stick=`, then extracts fields for each item. I prioritised semantic HTML (`role`, `aria-label`, `alt`, `title`) over class names. It also skips "show more" items and only includes images already present in the HTML (`data:image`, `encrypted-tbn`, or `knowledgecard` icons).
+
+The output is a hash where the key matches the search results selected tab (e.g., `artworks`, `cast`, `albums`). If no tab is selected, it defaults to `results`.
+
+### Structure
+
+- `lib/carousel_scraper.rb`: Orchestrates the extraction and chooses the correct carousel scope.
+- `lib/carousel_item_extractor.rb`: Extracts name, extensions, link, and image from a single item link.
+
+I tested against 3 other result pages to find common patterns:
+
+- "David Bowie albums" search: files/david-bowie-albums.html
+- "George Orwell books" search: files/george-orwell-books.html
+- "Lord of the Rings cast" search: files/lord-of-the-rings-cast.html
+
+### How to run
+
+Install dependencies:
+
+```
+bundle install
+```
+
+Run with the default Van Gogh paintings HTML (outputs to `files/van-gogh-paintings-expected-array.json`):
+
+```
+ruby main.rb
+```
+
+Run with a specific HTML file (outputs JSON to the same directory):
+
+```
+ruby main.rb files/david-bowie-albums.html # files/david-bowie-albums-expected-array.json
+ruby main.rb files/george-orwell-books.html # files/george-orwell-books-expected-array.json
+ruby main.rb files/lord-of-the-rings-cast.html # files/lord-of-the-rings-cast-expected-array.json
+```
+
+Run the tests:
+
+```
+bundle exec rspec
+```
diff --git a/files/david-bowie-albums.html b/files/david-bowie-albums.html
new file mode 100644
index 00000000..0e0e788a
--- /dev/null
+++ b/files/david-bowie-albums.html
@@ -0,0 +1,49 @@
+
https://en.wikipedia.org āŗ wiki āŗ David_Bowie_discogr...
Bowie released three more albums ā David Bowie (1969), The Man Who Sold the World (1970), and Hunky Dory (1971) ā before he eventually entered the UK Albums ...Read more
Bowie lanzó dos Ć”lbumes mĆ”s ā Space Oddity (1969), The Man Who Sold the World (1970) y Hunky Dory (1971) ā antes de llegar a entrar en la lista del UK Albums ...Read more
People also ask
What are David Bowie's albums in order?
How to listen to David Bowie's albums in chronological order
David Bowie (1967)
David Bowie (1969)
The Man Who Sold the World (1970)
Hunky Dory (1971)
The Rise and Fall of Ziggy Stardust and the Spiders from Mars (1972)
Mick Jagger (Facebook): David was always an inspiration to me and a true original. He was wonderfully shameless in his work. We had so many good times together. He was my friend, I will never forget him.
Studio albums Ā· David Bowie (1967) Ā· David Bowie (1969) Ā· The Man Who Sold The World (1970) Ā· Hunky Dory (1971) Ā· The Rise And Fall Of Ziggy Stardust And The ...Read more
https://rateyourmusic.com āŗ artist āŗ david-bowie
David Bowie discography and songs: Music profile for David Bowie, born 8 January 1947. Genres: Art Rock, Pop Rock, Glam Rock. Albums include The Rise and ...
1.Anna Calvi - Blackstar 2. Just Like - 'Tis A Pity She Was A Whore 3.David Fonseca - Lazarus 4.Maya Beiser - Prelude to Sue 5. Maya Beiser - ...Read more
Top answer: The master of reinvention. Still can't believe he's gone but what a legacy !
https://www.classical-music.com āŗ rock āŗ bowie-albums...
20 Nov 2025 ā Bowie albums ranked: all 26 studio LPs, from worst to best Ā· 26. Never Let Me Down (1987) Ā· 25. David Bowie (1967) Ā· 24. Tonight (1984).Read more
Hunky Dory, Rise and Fall of Ziggy Stardust, Station to Station, the Berlin trilogy (Heroes, Low, & Lodger to a lesser degree), Scary Monsters, and Black Star ...Read more
17 answers Ā· Top answer: Hunky Dory
+
+ Ziggy Stardust
+
+ Station to Station
+
+ Low
+
+ Blackstar
David Robert Jones, known as David Bowie, was an English singer, songwriter and actor. Regarded as among the most influential musicians of the 20th century, Bowie received particular acclaim for his work in the 1970s.Wikipedia
https://en.wikipedia.org āŗ wiki āŗ George_Orwell
George Orwell Ā· Down and Out in Paris and London (1933) Ā· The Road to Wigan Pier (1937) Ā· Homage to Catalonia (1938) Ā· Animal Farm (1945) Ā· Nineteen Eighty-Four ( ...Read more
About
Description
Eric Arthur Blair was an English novelist, poet, essayist, journalist, and critic who wrote under the pen name of George Orwell. His work is characterised by lucid prose, social criticism, opposition to all totalitarianism, and support of democratic socialism.Wikipedia
George Orwell is probably best known for his novels Animal Farm and Nineteen Eighty-Four. The latter was published in 1949 to great critical acclaim and has become hugely influential.31 Jul 2024
Cathy Lowne is a contributor to 501 Must-Read Books. Nineteen Eighty-four, novel by English author George Orwell published in 1949 as a warning against totalitarianism. The novel's chilling dystopia made a deep impression on readers, and Orwell's ideas entered mainstream culture in a way achieved by very few books.13 Jan 2026
Orwell wrote six novels: Burmese Days, A Clergyman's Daughter, Keep the Aspidistra Flying, Coming Up for Air, Animal Farm and Nineteen Eighty-Four. Most of these were semi-autobiographical.
https://en.wikipedia.org āŗ wiki āŗ George_Orwell_biblio...
Should I read 1984 or Animal Farm first?
Both overlap on themes such as perils of absolute power and authoritarianism, but can be read in either order. I've read and taught both. As others said, order doesn't matter, but Animal Farm is an easier read, often taught in 9th or 10th grade.1984 is much more challenging, but better in my opinion.22 Feb 2024
His unique political allegory Animal Farm was published in 1945, and it was this novel, together with the dystopia of Nineteen Eighty-Four (1949), which brought ...Read more
31 Jul 2024 ā George Orwell is probably best known for his novels Animal Farm and Nineteen Eighty-Four. The latter was published in 1949 to great critical ...Read more
https://en.wikipedia.org āŗ wiki āŗ George_Orwell_biblio...
The bibliography of George Orwell includes journalism, essays, novels, and non-fiction books written by the British writer Eric Blair (1903ā1950)Read more
22 May 2022 ā You've probably heard of George Orwell's most popular books, 1984 and Animal Farm. Just who is George Orwell and what books did he write?
The Complete Works of George Orwell: Novels, Poetry, Essays: (1984, Animal Farm, Keep the Aspidistra Flying, A Clergyman's Daughter, Burmese Days, Down ...Read more
Looking for books by George Orwell? See all books authored by George Orwell, including Nineteen Eighty-Four, and Animal Farm, and more on ThriftBooks.com.
https://www.goodreads.com āŗ list āŗ show āŗ 73762.Best_...
Best Of George Orwell Ā· 1. Animal Farm Ā· 2. 1984 Ā· 3. Down and Out in Paris and London Ā· 4. Burmese Days Ā· 5. Keep the Aspidistra Flying Ā· 6. Homage to ...Read more
Elijah Wood Ā· Frodo ; Ian McKellen Ā· Gandalf ; Orlando Bloom Ā· Legolas ; Alan Howard Ā· Voice of the Ring ; Noel Appleby Ā· Everard Proudfoot.Read more
https://en.wikipedia.org āŗ wiki āŗ The_Lord_of_the_Rin...
It features an ensemble cast including Elijah Wood, Ian McKellen, Liv Tyler, Viggo Mortensen, Sean Astin, Cate Blanchett, John Rhys-Davies, Billy Boyd, Dominic ...Read more
Cast ; Alan Howard Ā· Voice of the Ring ; Noel Appleby Ā· Everard Proudfoot ; Sean Astin Ā· Sam ; Sala Baker Ā· Sauron. /Goblin. /Uruk-hai ; Sean Bean at an event for The ...Read more
Starring Elijah Wood, Ian McKellen, Liv Tyler, Viggo Mortensen, Sean Astin, Cate Blanchett, John Rhys- Davies, Bernard Hill, Christopher Lee, ...Read more
18 Dec 2023 ā 'The Lord of the Rings' Trilogy Cast, Then and Now Ā· Elijah Wood (Frodo) Ā· Sean Astin (Sam) Ā· Ian McKellen (Gandalf) Ā· Viggo Mortensen (Aragorn).Read more
https://en.wikipedia.org āŗ wiki āŗ The_Lord_of_the_Rin...
Elijah Wood Ā· Ian McKellen Ā· Viggo Mortensen Ā· Sean Astin Ā· Liv Tyler Ā· Bernard Hill Ā· Cate Blanchett Ā· John Rhys-Davies Ā· Andy Serkis Ā· Billy Boyd Ā· Dominic ...Read more
Cast 117 Ā· Elijah Wood. Frodo Ā· Ian McKellen. Gandalf Ā· Viggo Mortensen. Aragorn Ā· Sean Astin. Sam Ā· Ian Holm. Bilbo Ā· Liv Tyler. Arwen Ā· Christopher Lee. Saruman.Read more
A ring with mysterious powers lands in the hands of a young hobbit, Frodo. Under the guidance of Gandalf, a wizard, he and his three friends set out on a journey and land in the Elvish kingdom.