-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .group import GroupSelector | ||
from .html import HtmlSelector | ||
from .image import ImageSelector | ||
from .item import ItemSelector | ||
from .link import LinkSelector | ||
from .text import TextSelector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from ..selector import Selector | ||
|
||
class ItemSelector(Selector): | ||
can_have_childs = True | ||
can_have_local_childs = True | ||
will_return_items = True | ||
|
||
def _get_data(self, parent_item): | ||
yield from self.get_items(parent_item) | ||
|
||
def _get_columns(self): | ||
return () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
|
||
from noscrapy.selectors import ItemSelector | ||
|
||
GET_DATA = { | ||
'single': | ||
(ItemSelector('a', css='p', many=False), '<p>a</p><p>b</p>', ['<p>a</p>']), | ||
'many': | ||
(ItemSelector('a', css='p'), '<p>a</p><p>b</p>', ['<p>a</p>', '<p>b</p>']), | ||
'none': | ||
(ItemSelector('a', css='p'), None, []), | ||
'no_elements': | ||
(ItemSelector('a', css='p'), '', []), | ||
'just_space': | ||
(ItemSelector('a', css='p'), ' ', []), | ||
} | ||
@pytest.mark.parametrize('selector,html,expected', list(GET_DATA.values()), ids=list(GET_DATA)) | ||
def test_item_selector_get_data(selector, html, expected): | ||
assert list(selector.get_data(html)) == expected | ||
|
||
def test_item_selector_columns(): | ||
assert ItemSelector('id').columns == () |