Skip to content

Commit

Permalink
Scrape editore notes on punchdrink
Browse files Browse the repository at this point in the history
  • Loading branch information
karlomikus committed Jun 7, 2024
1 parent bedc2b1 commit 6387fca
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/Scraper/Sites/PunchDrink.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function instructions(): ?string
$i++;
});

$result .= $this->parseEditorsNote();

return trim($result);
}

Expand All @@ -53,4 +55,17 @@ public function image(): ?array

return $image;
}

private function parseEditorsNote(): string
{
$editorsNote = $this->crawler->filterXPath('//h5[contains(text(), "Editor\'s Note")]/following::p')->html('');
// Convert <br> to new lines
$editorsNote = preg_replace('/<br\s?\/?>/ius', "\n\n", str_replace("\n", "", str_replace("\r", "", htmlspecialchars_decode($editorsNote))));
// Convert bolds to markdown
$editorsNote = preg_replace('/<(b|strong)>(.*?)<\/\1>/i', '### $2', $editorsNote);
$editorsNote = str_replace('&nbsp;', '', $editorsNote);

return "\n\n ## Editors note:\n\n" . htmlentities($editorsNote);
}
}

0 comments on commit 6387fca

Please sign in to comment.