-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch2.php
73 lines (62 loc) · 2.44 KB
/
search2.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
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Amazon Search</title>
<style>
td {
width: 15%;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
</head>
<body>
<?php
include('simple_html_dom.php');
function get_html_content($url) {
$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$string = curl_exec($ch);
curl_close($ch);
return $string;
}
error_reporting(0);
$db = new SQLite3('amazon.db');
$url = "http://www.amazon.com/s/ref=nb_sb_noss_2/182-8477515-7038932?url=search-alias%3Daps&field-keywords=table";
$url = preg_replace("|\s|", "+", $url);
$html = file_get_html($url);
foreach($html->find('li[id=result_0]') as $element) {
$image = $element->find('img', 0);
$title = $element->find('a', 1);
}
echo "<center><h2><b>Product</b></h2></center>";
echo "<center>".$image."</center>";
$title = preg_replace('|<a.*><h2.*>(.*)</h2></a>|iU', '\1' , $title);
echo "<center><h4>".$title."</h4></center>";
$results = $db->query('SELECT * FROM amz');
$tbl = "<table border='1' id='myTable' class='tablesorter'><thead><tr><th><b><h2><center>Date</center></h2></b></th><th><b><h2><center>Price</center></h2></b></th><th><b><h2><center>Condition</center></h2></b></th>
<th><b><h2><center>Seller</center></h2></b></th><td><b><h2><center>Logistics</center></h2></b></td></tr></thead><tbody>";
while ($row = $results->fetchArray()) {
$dat = $row[0]."";
$date = preg_replace('|^(.*)hihihi.*$|', '\1', $dat);
$tbl .= "<tr><td><center>".$date."</center></td><td><center>".$row[1]."</center></td><td><center>".$row[2]."</center></td><td><center>".$row[3]."</center></td><td><center>".$row[4]."</center></td></tr>";
}
$tbl .= "</tbody></table>";
$tbl = preg_replace('|<a.*>(.*)</a>|iU', '\1' , $tbl);
$tbl = preg_replace('|<form.*/form>|iU', '' , $tbl);
$tbl = preg_replace('|Read\smore|iU', '' , $tbl);
echo $tbl;
?>
<script>
function sortT() {
$("#myTable").tablesorter();
}
sortT();
</script>
</body>
</html>