-
Notifications
You must be signed in to change notification settings - Fork 11
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
9 changed files
with
46 additions
and
34 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,6 +1,6 @@ | ||
MYSQL_HOST=localhost:3306 | ||
MYSQL_HOST=127.0.0.1 | ||
MYSQL_PORT=3306 | ||
MYSQL_USER= | ||
MYSQL_PASSWORD= | ||
MYSQL_USER=root | ||
MYSQL_PASSWORD=root | ||
MYSQL_DB_NAME=test_cc | ||
MYSQL_TABLE_NAME=ccindex |
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
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,28 +1,30 @@ | ||
from bs4 import BeautifulSoup | ||
from cmoncrawl.common.types import PipeMetadata | ||
from cmoncrawl.processor.pipeline.extractor import BaseExtractor | ||
|
||
|
||
class MyExtractor(BaseExtractor): | ||
def __init__(self): | ||
# you can force a specific encoding if you know it | ||
super().__init__(encoding=None) | ||
def __init__(self): | ||
# you can force a specific encoding if you know it | ||
super().__init__(encoding=None) | ||
|
||
def extract_soup(self, soup: BeautifulSoup, metadata: PipeMetadata): | ||
# here you can extract the data you want from the soup | ||
# and return a dict with the data you want to save | ||
body = soup.select_one("body") | ||
if body is None: | ||
return None | ||
return {"body": body.get_text()} | ||
|
||
# You can also override the following methods to drop the files you don't want to extracti | ||
# Return True to keep the file, False to drop it | ||
def filter_raw(self, response: str, metadata: PipeMetadata) -> bool: | ||
return True | ||
|
||
def extract_soup(self, soup: BeautifulSoup, metadata: PipeMetadata): | ||
# here you can extract the data you want from the soup | ||
# and return a dict with the data you want to save | ||
body = soup.select_one("body") | ||
if body is None: | ||
return None | ||
return { | ||
"body": body.get_text() | ||
} | ||
def filter_soup(self, soup: BeautifulSoup, metadata: PipeMetadata) -> bool: | ||
return True | ||
|
||
# You can also override the following methods to drop the files you don't want to extracti | ||
# Return True to keep the file, False to drop it | ||
def filter_raw(self, response: str, metadata: PipeMetadata) -> bool: | ||
return True | ||
def filter_soup(self, soup: BeautifulSoup, metadata: PipeMetadata) -> bool: | ||
return True | ||
|
||
# Make sure to instantiate your extractor into extractor variable | ||
# The name must match so that the framework can find it | ||
extractor = MyExtractor() | ||
extractor = MyExtractor() |
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