Skip to content

Commit

Permalink
Add function to load external html files
Browse files Browse the repository at this point in the history
  • Loading branch information
wanLo authored and gitronald committed Nov 14, 2023
1 parent 51b07c4 commit 4a1e6c3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion WebSearcher/searchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def save_serp(self, save_dir='.', append_to=''):
"""Save SERP to file
Args:
save_dir (str, optional): Save results as `save_dir/{serp_id}.json`
save_dir (str, optional): Save results as `save_dir/{serp_id}.html`
append_to (str, optional): Append results to this file path
"""
assert self.html, "Must conduct a search first"
Expand Down Expand Up @@ -218,6 +218,19 @@ def save_serp(self, save_dir='.', append_to=''):

with open(fp, 'w') as outfile:
outfile.write(self.html)

def load_serp(self, serp_id:str, save_dir='.'):
"""Load SERP from file
Args:
serp_id (str): A unique identifier for the SERP to load
save_dir (str, optional): Load results from `save_dir/{serp_id}.html`
"""

fp = os.path.join(save_dir, f'{serp_id}.html')
with open(fp, 'r') as file:
self.html = file.read()
self.serp_id = serp_id


def parse_results(self, save_dir='.'):
Expand Down

0 comments on commit 4a1e6c3

Please sign in to comment.