-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.php
More file actions
100 lines (83 loc) · 2.46 KB
/
item.php
File metadata and controls
100 lines (83 loc) · 2.46 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
set_time_limit(24*60*60);
mysql_connect('localhost', 'root', '');
mysql_select_db('test');
include_once('simple_html_dom.php');
require_once 'model/initialize.php';
if(isset($_POST['url'])){
$count = 0;
$url = $_POST['url'];
$html = file_get_html($url);
$start = microtime(true);
foreach($html->find('a') as $item) {
if($count>12){
$url = $item->href;
$mobile_url = "http://www.mysmartprice.com/product/mobile/".substr($url, 35)."-other#techspec<br>";
$furl = str_replace("msp", "mst", $mobile_url);
mobile_details($furl);
}
$count++;
}
$end = number_format((microtime(true) - $start), 3);
echo "{$count} items took {$end} seconds";
}
function mobile_details($url){
$time = strftime("%Y-%m-%d %H:%M:%S", time()+60*60*5);
$count = 0;
$html = file_get_html($url);
//Mobile Details
$details = "";
foreach($html->find('div.item_details') as $spec) {
$details .= $spec->innertext;
}
//echo $details;
//Features
$features = "";
foreach($html->find('div.abt_text ul li') as $spec) {
$features .= "<p>".$spec->innertext."<p>";
}
//echo $features;
//Specification
$specification = "";
foreach($html->find('div.section-heading table tbody') as $spec) {
$specification .= $spec->innertext;
}
//echo $specification;
//item name
$name = $html->find('span[itemprop=name]', 0)->plaintext;
//item rating
$rating = $html->find('span[itemprop=ratingValue]', 0)->plaintext;
//item price
$price = $html->find('.price_val', 0)->plaintext;
$price_val = str_replace(",", "", $html->find('.price_val', 0)->plaintext);
//image
$image_link = $html->find('img[id=mspSingleImg]', 0)->src;
$image_name = substr($image_link, 51);
$product = new Product();
$product->category_id = '1';
$product->manufacturer_id = '1';
$product->name = $name;
$product->market_price = $price_val;
$product->short_desc = $features;
$product->spec = $specification;
$product->long_desc = $details;
$product->created = $time;
$product->crawled = $time;
if($product->save()){
$photo = new Photograph();
$photo->filename = $image_name;
$photo->created = $time;
if($photo->save()){
file_put_contents('images/'.$image_name, file_get_contents($image_link));
$image = new Image();
$image->photo_id = $photo->id;
$image->user_id = 1;
$image->property_id = $product->id;
$image->property = 'item';
if($image->save()){
echo $name." ...Done<br>";
}
}
}
}
?>