Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scrapy_splash/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SplashRequest(scrapy.Request):
It requires SplashMiddleware to work.
"""
def __init__(self,
url,
url=None,
callback=None,
method='GET',
endpoint='render.html',
Expand All @@ -48,6 +48,8 @@ def __init__(self,
meta=None,
**kwargs):

if url is None:
url = 'about:blank'
url = to_unicode(url)

meta = copy.deepcopy(meta) or {}
Expand Down
7 changes: 1 addition & 6 deletions scrapy_splash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import six

from scrapy.http import Headers
import scrapy
if scrapy.version_info >= (2, ):
from scrapy.utils.python import to_unicode
else:
from scrapy.utils.python import to_native_str as to_unicode
from scrapy.utils.python import to_bytes
from scrapy.utils.python import to_unicode, to_bytes


def dict_hash(obj, start=''):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries :: Python Modules',
],
install_requires=['scrapy', 'six'],
install_requires=['scrapy>=2.4', 'six'],
)
6 changes: 3 additions & 3 deletions tests/test_fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def requests():
dict(url=url2, args={'wait': 0.5}), # 5
dict(url=url3), # 6
dict(url=url2, method='POST'), # 7
dict(url=url3, args={'wait': 0.5}), # 8
dict(url=url3, args={'wait': 0.5}), # 9
dict(url=url3, args={'wait': 0.7}), # 10
dict(args={'wait': 0.5}), # 8
dict(args={'wait': 0.5}), # 9
dict(args={'wait': 0.7}), # 10
dict(url=url4), # 11
]
splash_requests = [SplashRequest(**kwargs) for kwargs in request_kwargs]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,21 @@ def test_cache_args():
assert mw._remote_keys == {}


def test_splash_request_no_url():
mw = _get_mw()
lua_source = "function main(splash) return {result='ok'} end"
req1 = SplashRequest(meta={'splash': {
'args': {'lua_source': lua_source},
'endpoint': 'execute',
}})
req = mw.process_request(req1, None)
assert req.url == 'http://127.0.0.1:8050/execute'
assert json.loads(to_unicode(req.body)) == {
'url': 'about:blank',
'lua_source': lua_source
}


def test_post_request():
mw = _get_mw()
for body in [b'', b'foo=bar']:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deps =
passenv = SPLASH_URL
deps =
{[common]deps}
scrapy
scrapy >= 2.4.0
commands =
pip install -e .
py.test --doctest-modules --doctest-glob '*.py,*.rst' --cov=scrapy_splash {posargs:README.rst scrapy_splash tests}