mirror of https://github.com/scrapy/scrapy.git
use netloc instead of hostname in url_is_from_any_domain(). closes #50
This commit is contained in:
parent
08d2c2b9ee
commit
b1f011d740
|
|
@ -15,6 +15,10 @@ class UrlUtilsTest(unittest.TestCase):
|
|||
self.assertTrue(url_is_from_any_domain(url, ['wheele-bin-art.co.uk']))
|
||||
self.assertFalse(url_is_from_any_domain(url, ['art.co.uk']))
|
||||
|
||||
url = 'http://192.169.0.15:8080/mypage.html'
|
||||
self.assertTrue(url_is_from_any_domain(url, ['192.169.0.15:8080']))
|
||||
self.assertFalse(url_is_from_any_domain(url, ['192.169.0.15']))
|
||||
|
||||
url = 'javascript:%20document.orderform_2581_1190810811.mode.value=%27add%27;%20javascript:%20document.orderform_2581_1190810811.submit%28%29'
|
||||
self.assertFalse(url_is_from_any_domain(url, ['testdomain.com']))
|
||||
self.assertFalse(url_is_from_any_domain(url+'.testdomain.com', ['testdomain.com']))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from scrapy.utils.python import unicode_to_str
|
|||
|
||||
def url_is_from_any_domain(url, domains):
|
||||
"""Return True if the url belongs to any of the given domains"""
|
||||
host = parse_url(url).hostname
|
||||
host = parse_url(url).netloc
|
||||
|
||||
if host:
|
||||
return any(((host == d) or (host.endswith('.%s' % d)) for d in domains))
|
||||
|
|
|
|||
Loading…
Reference in New Issue