forked from marshallbrekka/WebBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
63 lines (45 loc) · 1.14 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
<?php
require_once 'DOMParser.php';
require_once 'StringSearch.php';
/**
* Description of main
*
* @author Marshall
*/
class main {
private $search;
private $parser;
private $searchTerms = array(
'new' => 'New %p',
'used' => 'Used %p',
'marketplace' => 'Marketplace %p',
'semester' => 'Semester %p',
'quarter' => 'Quarter %p',
'60day' => '60 day %p'
);
public function getPrices($url) {
$searchResults = array();
$pattern = '/^\$[0-9]{1,}(.[0-9]{2})?$/i';
$start = time();
$this->parse = new DOMParser();
$source = $this->parse->parseFile($url);
$this->search = new StringSearch($source);
foreach($this->searchTerms as $key => $value) {
$result = $this->search->searchContainingPattern($value, $pattern);
print_r($result);
if(!$result) {
echo 'search failed';
}
if(!empty($result)) {
$searchResults[$key] = $result;
}
}
$end = time() - $start;
echo "\ntime it took in seconds " . $end;
return $searchResults;
}
}
$m = new main();
$url = 'http://www.textbooks.com/ISBN/9780321500243/Mario-F-Triola/Elementary-Statistics---With-CD_-_0321500245.php';
print_r($m->getPrices($url));
?>