Resultaten van SimpleHTMLDom in MySQL opslaan, hoe ?
Dit werkt dus overduidelijk niet. Hoe zou ik het moeten aanpakken ?
Eventueel andere dingen op te merken aan mijn script (als er een manier is om het makkelijker en overzichterlijker te maken hoor ik het graag :)).
Mochten er mensen geïnteresseerd zijn om mee te helpen:
https://code.google.com/p/supplementen-prijzenvergelijking/
supps.php
Code (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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
* supps.php
*
* Copyright 2011 Vlad Polianskii <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Supplementen Prijzenophaling</title>
</head>
<body>
<?php
// nodig om te scrapen
include ("simple_html_dom.php");
// verbinden met database
// MySQL connectie
$mysql_server = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'db_school';
// Eventueel foutmelding
@mysql_connect($mysql_server, $mysql_user, $mysql_pass) or die("Er kon geen verbinding worden gemaakt met de MySQL database.");
@mysql_select_db($mysql_db) or die("De database kon niet geselecteerd worden!");
/************************************************
* Variabelen *
* ---------- *
* $wp22kg = Whey Perfection 2,2kg *
* $wp45kg = Whey Perfection 4,5kg *
* $wd1kg = Whey Delicious 1,0kg *
* $wd25kg = Whey Delicious 2,5kg *
* $sf2kg = Iron Whey 2,0kg *
* $bl2kg = Whey Pro 2,0kg *
* *
* *
************************************************/
// DOM object creeëren
$html = new simple_html_dom();
// HTML ophalen Bodyenfitshop
$html -> load_file('http://bodyenfitshop.nl/whey-proteine/body-fit-sportsnutrition/whey-perfection');
// Prijs ophalen van B&FShop Whey Perfection dmv <td class=r>
// 2,2kg whey perfection
$wp22kg = $html -> find(".r", 2) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (1, \'Bodyenfitshop\', \'Whey Perfection\', \'2,2kg\', '".$wp22kg."');";
// 4,4kg whey perfection
$wp45kg = $html -> find(".r", 4) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (2, \'Bodyenfitshop\', \'Whey Perfection\', \'4,5kg\', '".$wp45kg."');";
// HTML ophalen XXL Nutrition
$html -> load_file('http://www.xxlnutrition.nl/whey-delicious/xxl-nutrition');
// Gewicht er uit halen, die schrijven wij er zelf bij
$pattern = array("/1000 gram » /", "/2500 gram » /");
// array maken voor info die wij er uit gaan laten
$html = preg_replace($pattern, '', $html);
// $pattern vervangen door niks
$html = str_get_html($html);
// DOM object maken van een string
// Prijs ophalen van XXL Nutrition Whey Delicious dmv <option value=*>
// 1kg whey delicious
$wd1kg = $html -> find('option[value=435]', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (3, \'XXL Nutrition\', \'Whey Delicious\', \'1,0kg\', '".$wd1kg."');";
// 2,5kg whey delicious
$wd25kg = $html -> find('option[value=437]', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (4, \'XXL Nutrition\', \'Whey Delicious\', \'2,5kg\', '".$wd25kg."');";
// HTML ophalen Sportsfood
$html -> load_file('http://www.sportfood.nl/shop/product_info.php?products_id=373');
// Prijs ophalen van Sportsfood Iron Whey dmv <td class=pageHeading>
// 2kg iron whey
$sf2kg = $html -> find('td[class=pageHeading]', 1) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (5, \'Sportfood\', \'Iron Whey\', \'2,0kg\', '".$sf2kg."');";
// HTML ophalen Bodylab
$html -> load_file('http://www.bodylab.nl/?pid=483');
// Prijs ophalen van Bodylab Whey Pro dmv class .rbprice
// 2kg whey pro
$bl2kg = $html -> find('.rbprice', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (6, \'Bodylab\', \'Whey Pro\', \'2,0kg\', '".$bl2kg."');";
// geheugen vrijmaken
$html->clear();
unset($html);
?>
</body>
</html>
/*
* supps.php
*
* Copyright 2011 Vlad Polianskii <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Supplementen Prijzenophaling</title>
</head>
<body>
<?php
// nodig om te scrapen
include ("simple_html_dom.php");
// verbinden met database
// MySQL connectie
$mysql_server = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'db_school';
// Eventueel foutmelding
@mysql_connect($mysql_server, $mysql_user, $mysql_pass) or die("Er kon geen verbinding worden gemaakt met de MySQL database.");
@mysql_select_db($mysql_db) or die("De database kon niet geselecteerd worden!");
/************************************************
* Variabelen *
* ---------- *
* $wp22kg = Whey Perfection 2,2kg *
* $wp45kg = Whey Perfection 4,5kg *
* $wd1kg = Whey Delicious 1,0kg *
* $wd25kg = Whey Delicious 2,5kg *
* $sf2kg = Iron Whey 2,0kg *
* $bl2kg = Whey Pro 2,0kg *
* *
* *
************************************************/
// DOM object creeëren
$html = new simple_html_dom();
// HTML ophalen Bodyenfitshop
$html -> load_file('http://bodyenfitshop.nl/whey-proteine/body-fit-sportsnutrition/whey-perfection');
// Prijs ophalen van B&FShop Whey Perfection dmv <td class=r>
// 2,2kg whey perfection
$wp22kg = $html -> find(".r", 2) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (1, \'Bodyenfitshop\', \'Whey Perfection\', \'2,2kg\', '".$wp22kg."');";
// 4,4kg whey perfection
$wp45kg = $html -> find(".r", 4) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (2, \'Bodyenfitshop\', \'Whey Perfection\', \'4,5kg\', '".$wp45kg."');";
// HTML ophalen XXL Nutrition
$html -> load_file('http://www.xxlnutrition.nl/whey-delicious/xxl-nutrition');
// Gewicht er uit halen, die schrijven wij er zelf bij
$pattern = array("/1000 gram » /", "/2500 gram » /");
// array maken voor info die wij er uit gaan laten
$html = preg_replace($pattern, '', $html);
// $pattern vervangen door niks
$html = str_get_html($html);
// DOM object maken van een string
// Prijs ophalen van XXL Nutrition Whey Delicious dmv <option value=*>
// 1kg whey delicious
$wd1kg = $html -> find('option[value=435]', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (3, \'XXL Nutrition\', \'Whey Delicious\', \'1,0kg\', '".$wd1kg."');";
// 2,5kg whey delicious
$wd25kg = $html -> find('option[value=437]', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (4, \'XXL Nutrition\', \'Whey Delicious\', \'2,5kg\', '".$wd25kg."');";
// HTML ophalen Sportsfood
$html -> load_file('http://www.sportfood.nl/shop/product_info.php?products_id=373');
// Prijs ophalen van Sportsfood Iron Whey dmv <td class=pageHeading>
// 2kg iron whey
$sf2kg = $html -> find('td[class=pageHeading]', 1) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (5, \'Sportfood\', \'Iron Whey\', \'2,0kg\', '".$sf2kg."');";
// HTML ophalen Bodylab
$html -> load_file('http://www.bodylab.nl/?pid=483');
// Prijs ophalen van Bodylab Whey Pro dmv class .rbprice
// 2kg whey pro
$bl2kg = $html -> find('.rbprice', 0) -> innertext;
// in mysql
$sql = "INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (6, \'Bodylab\', \'Whey Pro\', \'2,0kg\', '".$bl2kg."');";
// geheugen vrijmaken
$html->clear();
unset($html);
?>
</body>
</html>
Gewijzigd op 27/05/2011 23:46:43 door Vlad Polianskii
Code (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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/*
* supplementen-prijzenvergelijking.php
*
* Copyright 2011 Tuplad <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
* ***********************************************
* Variabelen *
* ---------- *
* $wp22kg = Whey Perfection 2,2kg *
* $wp45kg = Whey Perfection 4,5kg *
* $wd1kg = Whey Delicious 1,0kg *
* $wd25kg = Whey Delicious 2,5kg *
* $sf2kg = Iron Whey 2,0kg *
* $bl2kg = Whey Pro 2,0kg *
* *
* ********************************************** */
// notices over lege $_POST negeren
ini_set('display_errors', 1);
error_reporting(~E_NOTICE);
// config
$sqlhost = "127.0.0.1";
$sqluser = "root";
$sqlpass = "";
$sqldb = "db_school";
// verbinden met database
$oPDO = new PDO('mysql:host=' . $sqlhost . ';dbname=' . $sqldb . '', $sqluser, $sqlpass);
// error handling
$oPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// functie om SQL inserting te vergemakkelijken
function addToDB($id, $producent, $product, $gewicht, $prijs) {
// variabels global maken om ze in functie te gebruiken
global $oPDO;
// query klaarmaken en escapen dmv prepare
$oResult = $oPDO->prepare("INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (:id, :producent, :product, :gewicht, :prijs) ON DUPLICATE KEY UPDATE D_prijs=VALUES(D_prijs)");
// resultaat weergeven
if ($oResult) {
echo("<p>Query voor " . $producent . " / " . $product . " / " . $gewicht . " uitgevoerd!</p> \n");
} else {
echo("<p>Geen nieuwe queries uitgevoerd!</p>");
}
// vars binden
$oResult->bindParam(':id', $id);
$oResult->bindParam(':producent', $producent);
$oResult->bindParam(':product', $product);
$oResult->bindParam(':gewicht', $gewicht);
$oResult->bindParam(':prijs', $prijs);
// query uitvoeren
$oResult->execute();
}
// nodig om te scrapen
include ("simple_html_dom.php");
echo <<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Supplementen Prijzenophaling</title>
</head>
<body>
<h1>Prijzen Vergelijking Demo</h1>
<form name="action" action="supplementen-prijzenvergelijking.php" method="POST">
<button type="submit" name="update" value="update">Update!</button>
<button type="submit" name="view" value="view">View!</button>
</form>
END;
if ($_POST['update']) {
try {
// DOM object creeëren
$html = new simple_html_dom();
// HTML ophalen Bodyenfitshop - Whey Perfection
$html->load_file('http://bodyenfitshop.nl/whey-proteine/body-fit-sportsnutrition/whey-perfection');
// Prijs ophalen van B&FShop Whey Perfection dmv <td class=r>
// 2,2kg Whey Perfection
$wp22kg = $html->find(".r", 2)->innertext;
// in db steken
addToDB('1', 'Bodyenfitshop', 'Whey Perfection', '2,2kg', $wp22kg);
// 4,5kg Whey Perfection
$wp45kg = $html->find(".r", 4)->innertext;
// in db steken
addToDB('2', 'Bodyenfitshop', 'Whey Perfection', '4,5kg', $wp45kg);
// HTML ophalen XXL Nutrition
$html->load_file('http://www.xxlnutrition.nl/whey-delicious/xxl-nutrition');
// Gewicht er uit halen, die schrijven wij er zelf bij
$pattern = array("/1000 gram » /", "/2500 gram » /");
// array maken voor info die wij er uit gaan laten
$html = preg_replace($pattern, '', $html);
// $pattern vervangen door niks
$html = str_get_html($html);
// DOM object maken van een string
// Prijs ophalen van XXL Nutrition Whey Delicious dmv <option value=*>
// 1kg whey delicious
$wd1kg = $html->find('option[value=435]', 0)->innertext;
// in mysql
addToDB('3', 'XXL Nutrition', 'Whey Delicious', '1,0kg', $wd1kg);
// 2,5kg whey delicious
$wd25kg = $html->find('option[value=437]', 0)->innertext;
// in mysql
addToDB('4', 'XXL Nutrition', 'Whey Delicious', '2,5kg', $wd25kg);
// HTML ophalen Sportfood
$html->load_file('http://www.sportfood.nl/shop/product_info.php?products_id=373');
// Prijs ophalen van Sportfood Iron Whey dmv <td class=pageHeading>
// 2kg iron whey
$sf2kg = $html->find('td[class=pageHeading]', 1)->innertext;
// in mysql
addToDB('5', 'Sportfood', 'Iron Whey', '2,0kg', $sf2kg);
// HTML ophalen Bodylab
$html->load_file('http://www.bodylab.nl/?pid=483');
// Prijs ophalen van Bodylab Whey Pro dmv class .rbprice
// 2kg whey pro
$bl2kg = $html->find('.rbprice', 0)->innertext;
// in mysql
addToDB('6', 'Bodylab', 'Whey Pro', '2,0kg', $bl2kg);
} catch (PDOException $e) {
echo '<pre>';
echo 'Regelnummer: ' . $e->getLine() . '<br>';
echo 'Bestand: ' . $e->getFile() . '<br>';
echo 'Foutmelding: ' . $e->getMessage() . '<br>';
echo '</pre>';
}
} elseif ($_POST['view']) {
echo "<p>Hier wordt informatie uit de DB gehaald!</p>";
} else {
echo "<p>Kies een actie.</p>";
}
echo <<<END
</body>
</html>
END;
?>
/*
* supplementen-prijzenvergelijking.php
*
* Copyright 2011 Tuplad <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
* ***********************************************
* Variabelen *
* ---------- *
* $wp22kg = Whey Perfection 2,2kg *
* $wp45kg = Whey Perfection 4,5kg *
* $wd1kg = Whey Delicious 1,0kg *
* $wd25kg = Whey Delicious 2,5kg *
* $sf2kg = Iron Whey 2,0kg *
* $bl2kg = Whey Pro 2,0kg *
* *
* ********************************************** */
// notices over lege $_POST negeren
ini_set('display_errors', 1);
error_reporting(~E_NOTICE);
// config
$sqlhost = "127.0.0.1";
$sqluser = "root";
$sqlpass = "";
$sqldb = "db_school";
// verbinden met database
$oPDO = new PDO('mysql:host=' . $sqlhost . ';dbname=' . $sqldb . '', $sqluser, $sqlpass);
// error handling
$oPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// functie om SQL inserting te vergemakkelijken
function addToDB($id, $producent, $product, $gewicht, $prijs) {
// variabels global maken om ze in functie te gebruiken
global $oPDO;
// query klaarmaken en escapen dmv prepare
$oResult = $oPDO->prepare("INSERT INTO T_supplementen (D_id, D_producent, D_product, D_gewicht, D_prijs) VALUES (:id, :producent, :product, :gewicht, :prijs) ON DUPLICATE KEY UPDATE D_prijs=VALUES(D_prijs)");
// resultaat weergeven
if ($oResult) {
echo("<p>Query voor " . $producent . " / " . $product . " / " . $gewicht . " uitgevoerd!</p> \n");
} else {
echo("<p>Geen nieuwe queries uitgevoerd!</p>");
}
// vars binden
$oResult->bindParam(':id', $id);
$oResult->bindParam(':producent', $producent);
$oResult->bindParam(':product', $product);
$oResult->bindParam(':gewicht', $gewicht);
$oResult->bindParam(':prijs', $prijs);
// query uitvoeren
$oResult->execute();
}
// nodig om te scrapen
include ("simple_html_dom.php");
echo <<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Supplementen Prijzenophaling</title>
</head>
<body>
<h1>Prijzen Vergelijking Demo</h1>
<form name="action" action="supplementen-prijzenvergelijking.php" method="POST">
<button type="submit" name="update" value="update">Update!</button>
<button type="submit" name="view" value="view">View!</button>
</form>
END;
if ($_POST['update']) {
try {
// DOM object creeëren
$html = new simple_html_dom();
// HTML ophalen Bodyenfitshop - Whey Perfection
$html->load_file('http://bodyenfitshop.nl/whey-proteine/body-fit-sportsnutrition/whey-perfection');
// Prijs ophalen van B&FShop Whey Perfection dmv <td class=r>
// 2,2kg Whey Perfection
$wp22kg = $html->find(".r", 2)->innertext;
// in db steken
addToDB('1', 'Bodyenfitshop', 'Whey Perfection', '2,2kg', $wp22kg);
// 4,5kg Whey Perfection
$wp45kg = $html->find(".r", 4)->innertext;
// in db steken
addToDB('2', 'Bodyenfitshop', 'Whey Perfection', '4,5kg', $wp45kg);
// HTML ophalen XXL Nutrition
$html->load_file('http://www.xxlnutrition.nl/whey-delicious/xxl-nutrition');
// Gewicht er uit halen, die schrijven wij er zelf bij
$pattern = array("/1000 gram » /", "/2500 gram » /");
// array maken voor info die wij er uit gaan laten
$html = preg_replace($pattern, '', $html);
// $pattern vervangen door niks
$html = str_get_html($html);
// DOM object maken van een string
// Prijs ophalen van XXL Nutrition Whey Delicious dmv <option value=*>
// 1kg whey delicious
$wd1kg = $html->find('option[value=435]', 0)->innertext;
// in mysql
addToDB('3', 'XXL Nutrition', 'Whey Delicious', '1,0kg', $wd1kg);
// 2,5kg whey delicious
$wd25kg = $html->find('option[value=437]', 0)->innertext;
// in mysql
addToDB('4', 'XXL Nutrition', 'Whey Delicious', '2,5kg', $wd25kg);
// HTML ophalen Sportfood
$html->load_file('http://www.sportfood.nl/shop/product_info.php?products_id=373');
// Prijs ophalen van Sportfood Iron Whey dmv <td class=pageHeading>
// 2kg iron whey
$sf2kg = $html->find('td[class=pageHeading]', 1)->innertext;
// in mysql
addToDB('5', 'Sportfood', 'Iron Whey', '2,0kg', $sf2kg);
// HTML ophalen Bodylab
$html->load_file('http://www.bodylab.nl/?pid=483');
// Prijs ophalen van Bodylab Whey Pro dmv class .rbprice
// 2kg whey pro
$bl2kg = $html->find('.rbprice', 0)->innertext;
// in mysql
addToDB('6', 'Bodylab', 'Whey Pro', '2,0kg', $bl2kg);
} catch (PDOException $e) {
echo '<pre>';
echo 'Regelnummer: ' . $e->getLine() . '<br>';
echo 'Bestand: ' . $e->getFile() . '<br>';
echo 'Foutmelding: ' . $e->getMessage() . '<br>';
echo '</pre>';
}
} elseif ($_POST['view']) {
echo "<p>Hier wordt informatie uit de DB gehaald!</p>";
} else {
echo "<p>Kies een actie.</p>";
}
echo <<<END
</body>
</html>
END;
?>
Gewijzigd op 30/05/2011 20:31:48 door Vlad Polianskii