<base href> ignored when resolving relative URLs
What would you like to share?
I initially didn't open an Pull request for this because I thought it might be an edge case, but I noticed it affects several real websites.
Scrapling currently resolves relative links against the page URL without respecting the HTML <base href> tag. This affects urljoin(), follow(), LinkExtractor, and CrawlSpider.
For example:
- forum.vbulletin.com:
articlesresolves to/forum/articles(404) instead of/articles(200). - php.net/strlen: Relative links can resolve incorrectly, resulting in 404s or redirects.
- crawler-test.com/relative_base_source:** Also reproduces the issue.
Browsers, Scrapy, and lxml handle these links correctly. The issue appears to come from parser.py, where urljoin(self.url, relative_url) ignores the document's base URL.
Would it make sense to resolve and cache the first <base href> per document, or is this behavior intentional?
Additional information
No response
Hi! @yetval
I'd love to contribute to this issue. I've reviewed the problem and understand how ignoring the HTML <base href> tag can cause incorrect URL resolution across Response.follow(), LinkExtractor, and CrawlSpider.
I have experience with Python and backend development, and I'd be happy to investigate the parser implementation, add regression tests, and work on a fix.
Would you be open to assigning this issue to me? I'd love to contribute!
Thanks!