-
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.
refactor: Code organization and Pagination (#12)
* feat: changed loader to load whole data rather than 1000 rows from supabase * refactor: moved master-child to distrib * refactor: rename src to phantom * refactor: updated the crawl.yaml * refactor: moved parser from engine to utils * chore: final comments * docs: updated paths
- Loading branch information
1 parent
f7d6a3c
commit 6a0f991
Showing
19 changed files
with
88 additions
and
77 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
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
Empty file.
File renamed without changes.
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 @@ | ||
from bs4 import BeautifulSoup | ||
from .logger import Logger | ||
from urllib.parse import urlparse, urljoin | ||
import json | ||
import requests | ||
|
||
|
||
class Parser: | ||
def __init__(self, show_logs=True): | ||
self.show_logs = show_logs | ||
self.log = Logger(self.show_logs).log | ||
|
||
def clean_url(self, url): | ||
parsed = urlparse(url) | ||
cleaned = parsed.scheme + "://" + parsed.netloc + parsed.path | ||
return cleaned | ||
|
||
def fetch(self, url): | ||
response = requests.get(url) | ||
return response.content | ||
|
||
def parse(self, url): | ||
self.log(f"parsing {url}", "Parser") | ||
|
||
# cleaned_url = self.clean_url(url) since already cleaned disabled | ||
content = self.fetch(url) | ||
|
||
soup = BeautifulSoup(content, "html.parser") | ||
|
||
title = soup.title.string if soup.title else None | ||
|
||
text = soup.get_text() | ||
words = text.split() | ||
links = [urljoin(url, link.get("href")) for link in soup.find_all("a")] | ||
|
||
return links, words, url, title | ||
|
||
def url_parser(self, url): | ||
self.log(f"parsing {url}", "Parser") | ||
|
||
cleaned_url = self.clean_url(url) | ||
content = self.fetch(cleaned_url) | ||
|
||
soup = BeautifulSoup(content, "html.parser") | ||
title = soup.title.string | ||
return (title, cleaned_url) |
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