Initial commit
This commit is contained in:
46
src/MemoryQVLScraper.php
Normal file
46
src/MemoryQVLScraper.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Domain\Model\MemoryConfiguration;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class MemoryQVLScraper
|
||||
{
|
||||
/**
|
||||
* @param string $html
|
||||
* @return Collection|MemoryConfiguration[]
|
||||
*/
|
||||
public function scrape(string $html): Collection
|
||||
{
|
||||
$configurations = [];
|
||||
|
||||
$crawler = new Crawler();
|
||||
$crawler->addHtmlContent($html);
|
||||
$crawler->filterXPath('//tr')->each(function (Crawler $tr) use (&$configurations) {
|
||||
$tableData = $tr->filterXPath('//td');
|
||||
if ($tableData->count() === 0) {
|
||||
return;
|
||||
}
|
||||
$configurations[] = $this->fromTableData($tableData);
|
||||
});
|
||||
|
||||
return collect($configurations);
|
||||
}
|
||||
|
||||
private function fromTableData(Crawler $tableData): MemoryConfiguration
|
||||
{
|
||||
return new MemoryConfiguration(
|
||||
type: $tableData->eq(0)->text('DDR4'),
|
||||
vendor: $tableData->eq(1)->text(),
|
||||
speed: (int)$tableData->eq(2)->text(0),
|
||||
supportedSpeed: (int)$tableData->eq(3)->text(0),
|
||||
moduleSizeHr: $tableData->eq(4)->text(),
|
||||
module: $tableData->eq(5)->text(),
|
||||
chip: $tableData->eq(6)->text(),
|
||||
isDualSided: $tableData->eq(7)->text() === 'DS',
|
||||
dimmSocketSupport: $tableData->eq(8)->text(),
|
||||
overclockingSupport: strtolower($tableData->eq(9)->text('')),
|
||||
note: $tableData->eq(10)->text()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user