Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upScrapy should handle "invalid" relative URLs better #1304
Comments
|
By the way, this also fails:
- the request is filtered out because of #1225 and self.parse is never called. Crawling scrapy.org with Scrapy is not straightforward :) |
|
The most evil spider ever: looks innocent, but doesn't work for multiple reasons import scrapy
class ScrapySpider(scrapy.Spider):
name = 'scrapyspider'
def start_requests(self):
yield scrapy.Request("http://scrapy.org", self.parse_main)
def parse_main(self, response):
for href in response.xpath("//a/@href").extract():
yield scrapy.Request(response.urljoin(href), self.parse_link)
def parse_link(self, response):
print(response.url) |
|
Hello, is this still an open issue? If so myself and some colleagues would like to look into it |
|
@jlbren yeah, it is still open; help is appreciated! |
|
@kmike great, we will post updates as they come! |
|
Thanks @jlbren! Feel free to ask any questions and discuss it here. The issue doesn't look easy because it is a bug in urlparse.urljoin from standard library. Likely we'll have to add a workaround to https://github.com/scrapy/w3lib, but maybe there is another way to solve this, I don't know. |
|
@kmike thanks, that is a helpful starting point. We will definitely take you up on posting questions. I am working with a team of 2 other CS grad students so our aim is to try and make significant progress as a semester project. I imagine they will post any questions they encounter as well. |
|
Hello. I'm working with @jlbren on this issue and we can't seem to replicate it. We aren't getting any 400 bad request responses. Here is our output from running the 'evil spider' above.. Could anyone shed any light as to why we aren't seeing the expected erroneous behavior? |
|
@creider , if I understood this issue, you can reproduce it with something like this:
Here, the link extractor generates a link to
|
|
Also note that in Python 3 -- Python 3.5 at least, urljoin seems to be doing a better job:
|
|
I'm fine with closing this issue if the bug in Python 2-only. |
|
FTR: this issue is fixed in Python 3.5.2; it is still present in Python 3.4.6 and 2.7.13 |
|
I looked into this and think I've managed to fix this issue for python 2.7.13. |
|
I made a PR at scrapy/w3lib#104. Hope that helps solve this problem :) |
|
I am also having issues due to For example, all modern browsers tolerate extra slashes after Using > urljoin('http://base.com', 'http:////other.com')
http://base.com//other.comwhereas browsers would load UPDATE: I've just tried scurl and, as you would expect, it handles this case correctly (i.e. same as Chrome). Would be great if Scrapy could adopt it, or any other library that wraps actual browser implementation. |
Currently Scrapy can't extract links from http://scrapy.org/ page correctly because urls in page header are relative to a non-existing parent:
../download/,../doc/, etc. Browsers resolve these links ashttp://scrapy.org/download/andhttp://scrapy.org/doc/, while response.urljoin, urlparse.urljoin and our ink extractors resolve them ashttp://scrapy.org/../download/, etc. This results in 400 Bad Request responses.urlparse.urljoin is not correct (or not modern) here. In the URL Living Standard for browsers it is said: