-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetquotes.php
63 lines (47 loc) · 1.45 KB
/
getquotes.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 'includes/db.php';
include 'lib/phrases.php';
include 'includes/simple_html_dom.php';
$obj = new Phrases();
$count = 0;
for($i = 1; $i < 10; $i++){
$url = "http://www.goodreads.com/quotes/tag/education?page=".$i;
$html = file_get_html($url);
$quotes = $html->find(".leftContainer",0);
foreach ($quotes->find(".quote") as $value) {
// echo $value;
$img_src = $value->find(".leftAlignedImage",0);
if($img_src){
$img = $img_src->find("img",0);
$img_src = $img->src;
$idimg = explode("/",$img_src);
$cuatro = $idimg[4];
$cuatro = substr ($cuatro, 0, strlen($cuatro) - 1);
$cuatro = $cuatro."8";
$idimg[4] = $cuatro;
$img_src = implode("/",$idimg);
$quoteText = $value->find(".quoteText",0);
$author = $quoteText->find("a",0)->plaintext;
$quoteText->find("a",0)->outertext='';
$quoteText = strip_tags($quoteText);
$quoteText = trim($quoteText);
$quoteText = preg_replace("/&#?[a-z0-9]+;/i","",$quoteText);
$quoteText = addslashes($quoteText);
}else{
echo "nel";
}
if(strlen($quoteText) < 150){
lo if($quoteText != ""){
$added = $obj->addQuote($quoteText,$author,$img_src);
if($added){
$count++;
echo "Author: ".$author."<br>";
echo "Quote: ".$quoteText."<br>";
echo "Image: ".$img_src."<br><br>";
}
}
}
}
}
echo $count;
?>