-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConfigGenerator.php
49 lines (43 loc) · 1.29 KB
/
ConfigGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
use Scraper\Structure\AnchorField;
use Scraper\Structure\RegexField;
use Scraper\Structure\TextField;
require_once(__DIR__ . '/../vendor/autoload.php');
$configurationManager = \Scraper\Scrape\ConfigurationManager::getInstance(
__DIR__ . '/Data/git-repo.json'
);
$configuration = $configurationManager->getOrCreateConfiguration();
$configuration->setTargetXPath('//div[@class="explore-content"]');
$configuration->setRowXPath('//*[contains(@class,"repo-list")]/li');
$configuration->setFields(
[
new TextField(
[
'name' => 'repo_name',
'xpath' => './/div[1]/h3/a'
]
),
new AnchorField(
[
'name' => 'repo_url',
'xpath' => './/div[1]/h3/a',
]
),
new TextField(
[
'name' => 'description',
'xpath' => './/div[@class="py-1"]/p',
'canBeEmpty'=> true
]
),
new RegexField(
[
'name' => 'stars_today',
'xpath' => './/div[4]/span[@class="float-right"]',
'regex' => '/(\d*)\s[stars]/'
]
),
]
);
$configurationManager->save($configuration);
print_r($configurationManager->getConfiguration());