Skip to content

url supports relative paths #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scraper/src/config/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ConfigLoader:

nb_hits_max = 6000000

relative_url = False

def __init__(self, config):
data = self._load_config(config)

Expand Down
13 changes: 13 additions & 0 deletions scraper/src/strategies/default_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ def get_records_from_dom(self, current_page_url=None):
if self.dom is None:
sys.exit('DefaultStrategy.dom is not defined')

# Convert absolute URL to relative path
original_url = current_page_url
if self.config.relative_url and original_url:
from urllib.parse import urlparse
parsed = urlparse(original_url)
# Construct a relative path (including path, parameters, and query parameters)
relative_url = parsed.path
if parsed.params: # Handle URL parameters (less common)
relative_url += ';' + parsed.params
if parsed.query: # Handle query parameters
relative_url += '?' + parsed.query
current_page_url = relative_url

# Reset it to be able to have a clean instance when testing
self.global_content = {}

Expand Down
Loading