<?php ini_set('max_execution_time', 300); include "bot.php"; do { $return_array = http_get("http://duexam2.du.ac.in/RSLT_ND2015/Students/List_of_Declare_RSLT.aspx", "http://duexam2.du.ac.in/RSLT_ND2015/Students/Combine_GradeCard.aspx"); $html = $return_array['FILE']; } while ($html == ''); $dom = new DOMdocument(); @$dom->loadHTML($html); $xpath = new DOMxpath($dom); $tmp = $xpath->query("//span[@id='lblmsg']"); $s = $tmp->item(0)->nodeValue; echo $s; if ($s != "Sorry! no record found.") { $to = "*****@*****.**"; $subject = "Results Declared"; $body = "Hi\nUniversity of Delhi has declared some of results, check yours at\nhttp://duexam2.du.ac.in/RSLT_ND2015/Students/Combine_GradeCard.aspx\n\nAll the Best and Happy New Year 2016."; $header = "From: results@du.ac.in"; mail($to, $subject, $body, $header); $to = "*****@*****.**"; mail($to, $subject, $body, $header); $to = "*****@*****.**"; mail($to, $subject, $body, $header); }
<?php libxml_use_internal_errors(true); header("Content-Type: text/plain; charset=utf-8"); $str = <<<EOF <html> \t<head> \t\t<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> \t</head> \t<body> \t\t<p>Toto vas à la <b>plage</b>.</p> \t</body></div></b> </html> EOF; libxml_use_internal_errors(false); $str = strip_tags($str, "<meta><b><i>"); $doc = new DOMdocument(); $doc->loadHTML($str); $str = $doc->saveHTML(); echo $str;
$url = urlencode($_GET['url']); $type = urlencode($_GET['type']); if (filter_var($_GET['url'], FILTER_VALIDATE_URL)) { if ($type == 'stumbleupon') { $content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url={$url}"); $result = json_decode($content); if (isset($result->result->views)) { $json['count'] = $result->result->views; } } if ($type == 'googlePlus') { //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/ $content = file_get_contents("https://plusone.google.com/u/0/_/+1/fastbutton?url=" . urlencode($_GET['url']) . "&count=true"); $doc = new DOMdocument(); libxml_use_internal_errors(true); $doc->loadHTML($content); $doc->saveHTML(); $num = $doc->getElementById('aggregateCount')->textContent; $json['count'] = $num ? $num : '0'; } } echo str_replace('\\/', '/', json_encode($json)); function parse($encUrl) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => 'sharrre', CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 10, CURLOPT_MAXREDIRS => 3, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => false); $ch = curl_init(); $options[CURLOPT_URL] = $encUrl; curl_setopt_array($ch, $options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch);
function crawl_product_details($ASIN_URL, $ASIN, $uniqid) { // Crawl details from amazon try { $image1 = $image2 = $image3 = $image4 = $image5 = $image6 = $image7 = $image8 = $image9 = $image10 = ''; $body = file_get_contents($ASIN_URL); $title = $brand = $list_price = $price = $you_save = $shipping = $category = $description = $feature = ''; $doc = new DOMdocument(); libxml_use_internal_errors(true); $doc->loadHTML($body); $docxpath = new DOMXpath($doc); $title = $doc->getElementById('productTitle'); $brand = $doc->getElementById('brand'); $price = $doc->getElementById('priceblock_ourprice'); $you_save = $doc->getElementById('regularprice_savings'); $feature = $doc->getElementById('feature-bullets'); $available = FALSE; $shipping = "FREE"; $availablity_element = $docxpath->query('//span[@class="a-size-medium a-color-success"]'); foreach ($availablity_element as $availablity) { $available = TRUE; } if ($available == FALSE) { return; } if (isset($title->textContent)) { $title = $title->textContent; } if (isset($brand->textContent)) { $brand = $brand->textContent; } if (isset($price->textContent)) { $price = $price->textContent; } if (isset($you_save->textContent)) { $you_save = $you_save->textContent; } if (isset($feature->textContent)) { $feature = $feature->textContent; } $image_element = $doc->getElementById('landingImage'); $images = $image_element->getAttribute('data-a-dynamic-image'); $regex = '/\\b(https?|ftp|file|http):\\/\\/[-A-Z0-9+&@#\\/%?=~_|$!:,.;]*[A-Z0-9+&@#\\/%=~_|$]/i'; preg_match_all($regex, $images, $matches); $urls = $matches[0]; // go over all links $i = 0; foreach ($urls as $url) { if (strpos($url, 'L.jpg') !== false) { $i++; ${'image' . $i} = $url; } } $list_prices = $docxpath->query('//td[@class="a-span12 a-color-secondary a-size-base a-text-strike"]'); foreach ($list_prices as $list_price) { $list_price = $list_price->textContent; } $shipping_prices = $docxpath->query('//span[@class="a-size-small a-color-secondary shipping3P"]'); foreach ($shipping_prices as $shipping_price) { $shipping_price = $shipping_price->textContent; $shipping_price = preg_replace('/[a-zA-Z]+/', '', $shipping_price); $shipping_price = str_replace('+', '', $shipping_price); $shipping_price; } $category_element = $docxpath->query('//a[@class="nav-a nav-b"]'); foreach ($category_element as $category_meta) { $category = $category_meta->textContent; } $description_element = $doc->getElementsByTagName('meta'); foreach ($description_element as $description_meta) { if ($description_meta->getAttribute('name') === 'description') { $description = $description_meta->getAttribute('content'); } } /* $Product = array( 'ASIN' => $ASIN, 'Title' => $title, 'Brand' => $brand, 'List Price' => $list_price, 'Price' => $price, 'You Save' => $you_save, 'Shipping' => $shipping, 'Category' => $category, 'Description' => $description, 'Feature' => $feature, 'Image1' => $image1, 'Image2' => $image2, 'Image3' => $image3, 'Image4' => $image4, 'Image5' => $image5, 'Image6' => $image6, 'Image7' => $image7, 'Image8' => $image8, 'Image9' => $image9, 'Image10' => $image10 );*/ $product = array($ASIN, $title, $brand, $list_price, $price, $you_save, $shipping, $category, $description, $feature, $image1, $image2, $image3, $image4, $image5, $image6, $image7, $image8, $image9, $image10); $GLOBALS['count'] = $GLOBALS['count'] + 1; if ($GLOBALS['count'] % 100 == 0) { sleep(5); } $upload_dir = wp_upload_dir(); $fileOutput = $upload_dir['path'] . '/' . $uniqid . '.csv'; $fp = fopen($fileOutput, "a"); fputcsv($fp, $product); fclose($fp); } catch (Exception $e) { print $e; } }