Skip to content

Commit 5e4bce3

Browse files
authored
Merge pull request #324 from protokoul/fix/splashrequest-url-required
Change url from required to optional parameter for SplashRequest
2 parents 538f4d1 + 2ea59d9 commit 5e4bce3

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

scrapy_splash/request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SplashRequest(scrapy.Request):
3131
It requires SplashMiddleware to work.
3232
"""
3333
def __init__(self,
34-
url,
34+
url=None,
3535
callback=None,
3636
method='GET',
3737
endpoint='render.html',
@@ -48,6 +48,8 @@ def __init__(self,
4848
meta=None,
4949
**kwargs):
5050

51+
if url is None:
52+
url = 'about:blank'
5153
url = to_unicode(url)
5254

5355
meta = copy.deepcopy(meta) or {}

scrapy_splash/utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
import six
66

77
from scrapy.http import Headers
8-
import scrapy
9-
if scrapy.version_info >= (2, ):
10-
from scrapy.utils.python import to_unicode
11-
else:
12-
from scrapy.utils.python import to_native_str as to_unicode
13-
from scrapy.utils.python import to_bytes
8+
from scrapy.utils.python import to_unicode, to_bytes
149

1510

1611
def dict_hash(obj, start=''):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
'Topic :: Software Development :: Libraries :: Application Frameworks',
3131
'Topic :: Software Development :: Libraries :: Python Modules',
3232
],
33-
install_requires=['scrapy', 'six'],
33+
install_requires=['scrapy>=2.4', 'six'],
3434
)

tests/test_fingerprints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def requests():
142142
dict(url=url2, args={'wait': 0.5}), # 5
143143
dict(url=url3), # 6
144144
dict(url=url2, method='POST'), # 7
145-
dict(url=url3, args={'wait': 0.5}), # 8
146-
dict(url=url3, args={'wait': 0.5}), # 9
147-
dict(url=url3, args={'wait': 0.7}), # 10
145+
dict(args={'wait': 0.5}), # 8
146+
dict(args={'wait': 0.5}), # 9
147+
dict(args={'wait': 0.7}), # 10
148148
dict(url=url4), # 11
149149
]
150150
splash_requests = [SplashRequest(**kwargs) for kwargs in request_kwargs]

tests/test_middleware.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,21 @@ def test_cache_args():
630630
assert mw._remote_keys == {}
631631

632632

633+
def test_splash_request_no_url():
634+
mw = _get_mw()
635+
lua_source = "function main(splash) return {result='ok'} end"
636+
req1 = SplashRequest(meta={'splash': {
637+
'args': {'lua_source': lua_source},
638+
'endpoint': 'execute',
639+
}})
640+
req = mw.process_request(req1, None)
641+
assert req.url == 'http://127.0.0.1:8050/execute'
642+
assert json.loads(to_unicode(req.body)) == {
643+
'url': 'about:blank',
644+
'lua_source': lua_source
645+
}
646+
647+
633648
def test_post_request():
634649
mw = _get_mw()
635650
for body in [b'', b'foo=bar']:

0 commit comments

Comments
 (0)