Repository navigation
fix(nodes): keep the scheme of absolute URLs extracted by ParseNode - #1172
Open
MohammadHijjawi97 wants to merge 1 commit into
Open
MohammadHijjawi97 wants to merge 1 commit into
MohammadHijjawi97 wants to merge 1 commit into
Conversation
The scheme part of ParseNode.url_pattern was written as a character class, so the match never captured "http(s)://". Absolute links and image URLs were then joined onto the page URL as if they were relative (https://docs.example.org/guide on https://example.com/blog/post became https://example.com/blog/docs.example.org/guide), and dropped entirely when the source was local HTML. This affects the link_urls and img_urls used by OmniScraperGraph.
This branch has not been deployed
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.
Summary
ParseNode.url_patternbegins with[http[s]?:\/\/]?, which is a character class rather than an optionalhttp(s)://group. The scheme is therefore never part of the match. Whenparse_urls=True(OmniScraperGraph), every absolute link or image URL loses its scheme and is then joined onto the page URL as if it were relative:With a local HTML source the same URLs were dropped entirely, because only results starting with
httpare kept. The brokenimg_urlsare the ones OmniScraperGraph sends toImageToTextNode.Changes
(https?:\/\/). The pattern already required://, so the set of matched URLs is unchanged; they now keep their scheme. Relative URLs are still resolved against the page URL.tests/nodes/parse_node_test.pycovering absolute and relative links and images, a local source, andexecute()withparse_urls=True.Testing
pytest tests/nodes/parse_node_test.py: 3 failed onpre/beta, 3 passed with the fix.pytest tests/test_error_page_detection.py: passes.ruff check,black --checkandisort --check-onlyon the changed files, at the versions pinned in.pre-commit-config.yaml.