-
Notifications
You must be signed in to change notification settings - Fork 0
/
generatecontent.php
executable file
·71 lines (66 loc) · 2.58 KB
/
generatecontent.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
<?php
$numargs = count($argv);
$keywords = "";
for( $i = 1; $i < $numargs ; $i++ ) {
$keywords = $keywords . $argv[$i] . "+";
}
$len = strlen( $keywords);
$keywords = substr( $keywords, 0 , $len - 1 );
#echo $keywords;
mkdir($keywords);
chdir($keywords);
$url = "http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=LaurensM-9ccd-4d15-8eba-9602a1a3f606&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=$keywords";
$response = file_get_contents($url);
$xml = simplexml_load_string( $response );
$count = $xml->searchResult[0]['count'];
echo "Number of results found: " . $count . "\n";
if ($count < 100) {
die("Too few results: $count \n");
}
for ($i = 0; $i < $count ; $i++) {
$ItemID = $xml->searchResult->item[$i]->itemId;
echo($ItemID);
$singleitemurl = "http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=XML&appid=LaurensM-9ccd-4d15-8eba-9602a1a3f606&siteid=0&version=515&ItemID=" . "$ItemID" . "&IncludeSelector=Description,ItemSpecifics";
$resp = file_get_contents($singleitemurl);
$obj = new SimpleXMLElement($resp);
$html = $obj->Item[0]->Description;
$itemurl = $obj->Item[0]->PictureURL;
$html = strip_html_tags($html);
$html = replaceWhitespace($html);
$html = preg_replace('~<\s*\bscript\b[^>]*>(.*?)<\s*\/\s*script\s*>~is', '', $html);
$body = strip_tags($html);
#$body = "<img src=\"$itemurl\">" . "$body";
$file = 'search.txt';
file_put_contents($file, $body, FILE_APPEND | LOCK_EX);
file_put_contents($keywords . $i, $body);
}
function strip_html_tags($str){
$str = preg_replace('/(<|>)\1{2}/is', '', $str);
$str = preg_replace(
array(// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
),
"", //replace above with nothing
$str );
$str = replaceWhitespace($str);
$str = strip_tags($str);
return $str;
} //function strip_html_tags ENDS
//To replace all types of whitespace with a single space
function replaceWhitespace($str) {
$result = $str;
foreach (array(
" ", " \t", " \r", " \n",
"\t\t", "\t ", "\t\r", "\t\n",
"\r\r", "\r ", "\r\t", "\r\n",
"\n\n", "\n ", "\n\t", "\n\r",
) as $replacement) {
$result = str_replace($replacement, $replacement[0], $result);
}
return $str !== $result ? replaceWhitespace($result) : $result;
}
############################
?>