Skip to content

Fix HTML link extraction in the web crawler - #43

Open
sumitsharma01 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
sumitsharma01:fix/html-link-extraction
Open

sumitsharma01 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
sumitsharma01:fix/html-link-extraction

Conversation

@sumitsharma01

Copy link
Copy Markdown

The web crawler's link regex skips URLs with fragments, such as /guide#schema, and unquoted href values. It also leaves HTML entities in URLs, so /search?a=1&b=2 is returned with a literal &.

This replaces the regex with Python's built-in HTMLParser to read href attributes. Links are then resolved against the page URL, stripped of fragments, and deduplicated. Empty links, fragment-only links, and unsupported schemes are still skipped. The parser also avoids treating links inside comments, script text, or data-href attributes as crawl targets.

Added tests through fetch_and_parse for the three URL cases, filtering, and deduplication. All four new test cases fail before the fix and pass after it. The full suite passes with 43 tests, and git diff --check passes. No new dependencies are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant