Extract Van Gogh Paintings Carousel#389
Open
Simar-malhotra09 wants to merge 8 commits into
Open
Conversation
Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
…resolver Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
…d schema Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
…d spec Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
…lity Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
Signed-off-by: Simar Malhotra <malhotrasimar009@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract Van Gogh Paintings Carousel
Ruby parser that reads
files/van-gogh-paintings.htmland extracts each painting's:The output matches the provided
expected-array.jsonexactly.All data is parsed from the local HTML file. No network requests are made.
Approach
Identifying carousel items
The main challenge is determining which elements belong to the carousel.
Google's CSS class names are generated and obfuscated (
pgNMRc,iELo6, etc.). They do not carry meaning and can change at any time, so the parser does not rely on them.Instead, carousel items are identified using the
stick=query parameter in the link URL. Any<a>element with a/search?...&stick=...URL that wraps an<img>is treated as a carousel item.This relies on Google's search URL structure rather than presentation specific CSS classes, making it a more stable signal.
Extracting metadata
The painting name and year are read from the innermost text nodes within each anchor element.
The year is only added to
extensionswhen it matches a four digit year:/\A\d{4}\z/This prevents title fragments from being incorrectly included in the extensions field.
Image extraction
The HTML contains two thumbnail formats.
Images embedded in scripts
The first set of paintings stores image data inside inline
<script>blocks through_setImagesSrc(ii, s)calls.During initialization, the parser:
\x3dto=Images from
data-srcThe remaining paintings are lazy loaded and expose the image URL directly through the
data-srcattribute.These images are read directly from the corresponding
<img>elements.Validation
The parser was tested against three carousel layouts:
files/van-gogh-paintings.htmlspec/fixtures/deniro-movies.htmlspec/fixtures/shinkai-books.htmlRunning