-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(website): add subscription example
- Loading branch information
Showing
9 changed files
with
131 additions
and
36 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
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 |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
|
||
# Configuration | ||
|
||
- [Website](./website.md) | ||
- [Environment](./env.md) | ||
|
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,40 @@ | ||
# Website | ||
|
||
The website class is the foundation to Spider. | ||
|
||
## Builder | ||
|
||
We use the builder pattern to configure our crawler. | ||
|
||
```python | ||
import asyncio | ||
|
||
from spider_rs import Website | ||
|
||
async def main(): | ||
website = Website("https://choosealicense.com", False).with_headers({ "authorization": "myjwttoken" }) | ||
|
||
asyncio.run(main()) | ||
``` | ||
|
||
## Subscriptions | ||
|
||
```python | ||
import asyncio | ||
|
||
from spider_rs import Website | ||
|
||
class Subscription: | ||
def __init__(self): | ||
print("Subscription Created...") | ||
def __call__(self, page): | ||
print(page.url + " - status: " + str(page.status_code)) | ||
# uncomment to perform extra parsing and get the page title | ||
# print(page.url + " - title: " + page.title()) | ||
|
||
async def main(): | ||
website = Website("https://choosealicense.com", False) | ||
website.crawl(Subscription()) | ||
|
||
asyncio.run(main()) | ||
``` |
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,15 @@ | ||
import asyncio | ||
|
||
from spider_rs import Website | ||
|
||
class Subscription: | ||
def __init__(self): | ||
print("Subscription Created...") | ||
def __call__(self, page): | ||
print(page.url + " - status: " + str(page.status_code)) | ||
|
||
async def main(): | ||
website = Website("https://choosealicense.com", False) | ||
website.crawl(Subscription()) | ||
|
||
asyncio.run(main()) |
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
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
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