File tree Expand file tree Collapse file tree 5 files changed +23
-11
lines changed
Expand file tree Collapse file tree 5 files changed +23
-11
lines changed Original file line number Diff line number Diff 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 {}
Original file line number Diff line number Diff line change 55import six
66
77from 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
1611def dict_hash (obj , start = '' ):
Original file line number Diff line number Diff line change 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)
Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff 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+
633648def test_post_request ():
634649 mw = _get_mw ()
635650 for body in [b'' , b'foo=bar' ]:
You can’t perform that action at this time.
0 commit comments