-
-
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.
Merge pull request #12 from Hardeepex/sweep/provide_me_all_css_select…
…ors_for_content_1 Sweep: provide me all css selectors for content for selectolax (✓ Sandbox Passed)
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
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
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,46 @@ | ||
import unittest | ||
|
||
from scrapeghost import CSS, SchemaScraper | ||
|
||
|
||
class TestNewScraper(unittest.TestCase): | ||
def setUp(self): | ||
self.scraper = SchemaScraper( | ||
{ | ||
"url": "url", | ||
"title": "str", | ||
"image": "str", | ||
"dealer": "str", | ||
"comments_count": "int", | ||
}, | ||
extra_preprocessors=[CSS("div.list_item"), CSS("a.offer_image"), CSS("h2.offer_title"), CSS("p.offer_description")], | ||
) | ||
|
||
def test_scrape(self): | ||
test_webpage = """ | ||
<div class="list_item"> | ||
<a href="test_url" class="offer_image"> | ||
<img src="test_image.jpg"> | ||
</a> | ||
<div class="list_item_body"> | ||
<p class="offer_dealer">Test Dealer</p> | ||
<h2 class="offer_title">Test Title</h2> | ||
<p class="offer_description">Test Description</p> | ||
</div> | ||
<ul class="list_item_counters"> | ||
<li class="offer_comment_counter">5</li> | ||
</ul> | ||
</div> | ||
""" | ||
result = self.scraper.scrape(test_webpage) | ||
expected_data = { | ||
"url": "test_url", | ||
"title": "Test Title", | ||
"image": "test_image.jpg", | ||
"dealer": "Test Dealer", | ||
"comments_count": 5, | ||
} | ||
self.assertEqual(result.data, expected_data) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |