-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.php
52 lines (43 loc) · 1.35 KB
/
parser.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
47
48
49
50
51
52
<?php
/*
* Name: Round Ir Crawler
* Date: 2022/10/07
* Author: Max Base
* Repository: https://github.com/basemax/RoundIrCrawler
*/
@mkdir("cache/");
function parsePage(int $page) {
$link = "https://www.rond.ir/SearchSimSale?page=" . $page;
$data = file_get_contents($link);
// $data = file_get_contents("cache-page1.html");
// print $data;
file_put_contents("cache/cache-page$page.html", $data);
$pattern = '/<tr class=(evendTr|odTr)>(.*?)<\/tr>/si';
preg_match_all($pattern, $data, $matches);
// print_r($matches[2]);
foreach ($matches[2] as $row_item) {
// print $row_item;
$pattern = '/>([0-9 ]+)<\/a>/si';
preg_match($pattern, $row_item, $phone_match);
// print_r($phone_match);
$pattern = '/<span>([0-9,]+)<\/span>/si';
preg_match($pattern, $row_item, $price_match);
// print_r($price_match);
if (isset($phone_match[1])) {
$phone = str_replace(" ", "", $phone_match[1]);
$price = null;
if (isset($price_match[1])) {
$price = str_replace(",", "", $price_match[1]);
}
print "$phone\t$price\n";
} else {
continue;
}
// break;
}
}
// Main
for ($i = 1; $i <= 8; $i++) {
parsePage($i);
// break;
}