Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change url from required to optional parameter for SplashRequest #324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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