Skip to content

Instantly share code, notes, and snippets.

@AABur
Last active April 15, 2021 11:58
Show Gist options
  • Select an option

  • Save AABur/ee8206c492d0c5d92d52c595d0e42923 to your computer and use it in GitHub Desktop.

Select an option

Save AABur/ee8206c492d0c5d92d52c595d0e42923 to your computer and use it in GitHub Desktop.
# coding: utf-8
import lxml.html
from .abstract import get_strategy
import pytest
class TestTags:
@pytest.mark.parametrize('start_urls_url, actual_url',
[('http://foo.bar/api', 'http://foo.bar/api'),
('http://foo.bar/api', 'http://foo.bar/api/test'),
('http://foo.bar/.*', 'http://foo.bar/api/test')])
def test_regex_start_urls_params(self, start_urls_url, actual_url):
# Given
# Stub ENV variables read by ConfigLoader
strategy = get_strategy({
'start_urls': [
{
'url': start_urls_url,
'tags': ["test"]
}
],
'selectors': {
"lvl0": "h1",
"lvl1": "h2",
"lvl2": "h3",
"content": "p"
}
})
strategy.dom = lxml.html.fromstring("""
<html><body>
<h1>Foo</h1>
</body></html>
""")
# When
actual = strategy.get_records_from_dom(actual_url)
# Then
assert actual[0]['tags'] == ["test"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment