function upload2bcsbyurl($remote, $url) { global $bcs; $name = basename($url); $local = './objs/' . time() . '_' . $name; curl_download($url, $local); $response = $bcs->create_object(BCS_BUCKET, $remote, $local); unlink($local); echo 'upload "' . $remote . '" to bcs!' . '<br/>'; }
function cache_get($url, $cache_file, $verbose = true, $update = false, $cache_life = 43200) { $message = ''; $content = ''; clearstatcache(); if ($url == '') { $message .= '[empty url]'; } else { if (file_exists($cache_file) && time() - filemtime($cache_file) <= $cache_life) { $message .= '[use cache]'; $content = @file_get_contents($cache_file); } else { $message .= '[update cache : '; if ($update && file_exists($cache_file) && curl_get_file_size($url) <= filesize($cache_file)) { $message .= 'cache file is already bigger'; $content = @file_get_contents($cache_file); } else { if (($content = curl_download($url)) !== false) { // @file_get_contents($url) rmkdir(dirname($cache_file)); if (($size = @file_put_contents($cache_file, $content)) === false) { $message .= 'not updatable (' . $cache_file . ')'; } else { $message .= 'updated (' . human_filesize($size) . ')'; } if (strpos($url, 'http://www.magic-ville.com') !== false) { time_nanosleep(0, 500000000); } // Avoid anti-leech mechanism on MV (30 queries every 15 sec) } else { $message .= 'not downloadable (' . $url . ')'; } } $message .= ']'; } } if ($verbose) { echo $message; } return $content; }
"> <input type="submit" value="提交"/> </form> <?php } elseif ($_GET['a'] == '1') { $key = $_REQUEST['key']; $url = $_REQUEST['url']; $name = daddslashes($_REQUEST['name']); $verifycode = $_POST['verify']; if (!isset($verifycode) || $verifycode != $verify) { echo '<hr/><font color="red">文件上传失败!请不要重复提交!</font>'; exit; } $name2 = md5(time() . rand()); $cache_file = $cachedir . $name2; $con = curl_download($url, $cache_file); if (!$con) { echo '远程获取文件失败,请检查URL地址是否正确!'; } else { $name2 = md5_file($cache_file); $row = $DB->get_row("SELECT * FROM udisk WHERE fileurl='{$name2}'"); if ($row) { $extension = explode('.', $row['filename']); if (($length = count($extension)) > 1) { $ext = strtolower($extension[$length - 1]); } $exti = '.' . $ext; echo '<font color="green">本站已存在该文件!</font><br/>文件名称:' . $row['filename'] . '<br/>文件类型:' . $row['type'] . '<br/>文件大小:' . size($row['size']) . '<br/>下载地址:<a href="../down.php/' . $name2 . $exti . '">' . $u . 'down.php/' . $name2 . $exti . '</a><br/>在线预览:<a href="list.php?act=view&name=' . $name2 . '" target="_blank">点击进入</a>'; } else { $result = $stor->savefile($name2, $cache_file); if (false == $result) {
} } if (empty($posts_not_displayed)) { $posts_not_displayed = array(); } echo 'new section<br />'; $post_id = $_POST['post_id']; $post_end = $post_id + 20; while ($post_id < $post_end) { if (in_array($post_id, $posts_not_displayed)) { $post_id++; continue; } echo '<br />ID: ' . $post_id; $url = 'http://www.prescott-az.gov/events/index.php?id=' . $post_id; $status = curl_download($url, $post_id); print_r($status); if ($status[1] == true) { echo $status[0] . ' was posted'; } if ($status[1] == false && !empty($status[0])) { echo $status[0] . ' was NOT posted'; $posts_not_displayed[] = $status[0]; print_r($posts_not_displayed); } $post_id++; } print_r($posts_not_displayed); update_option('posts_not_displayed', $posts_not_displayed); } else { // If Not submitted
function curl_download($Url) { $tmpfname = dirname(__FILE__) . '/cookie.txt'; if (!function_exists('curl_init')) { die('cURL is not installed. Install and try again.'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname); curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close($ch); return $output; } $name = "coryrichards"; //change for desired username $test = curl_download("https://www.instagram.com/" . $name . '/'); $pattern = '/window._sharedData.*;/'; preg_match($pattern, $test, $matches, PREG_OFFSET_CAPTURE, 3); $i = substr_replace($matches[0][0], '', 0, 20); $i = substr_replace($i, '', strlen($i) - 1, 20); $json = json_decode($i); $media = $json->entry_data->ProfilePage[0]->user->media->nodes; //var_dump($media); //uncomment to get extra options in object foreach ($media as $var) { echo '<img src="' . $var->display_src . '" />'; echo '<br>'; echo $var->caption; echo '<br>'; }
public function doParse($s_url, $a_config = array()) { //保存页面号 $this->vanpeople_id = str_replace('.html', '', basename($s_url)); $this->_config = $a_config; $html = file_get_html($s_url); $dom_main = $html->find('div[class=side]', 0); if (null == $dom_main) { return false; } //标题 $dom_caption = $dom_main->find('h1', 0); $this->title = $dom_caption->innertext; //原黄页信息发布时间 $dom_ep_info = $dom_main->find('div[class=ep_info]', 0); $s_dateinfo = $dom_ep_info->first_child()->innertext; $s_date = $this->getDateStrByStr($s_dateinfo); $this->vanpeople_time = $s_date == 0 ? 0 : strtotime($s_date); echo "this->vanpeople_time:{$this->vanpeople_time}<br/>"; $dom_info = $dom_main->find('div[class=ep_news]', 0); $dom_info_left = $dom_info->find('div[class=l]', 0); $a_dom_linfos = $dom_info_left->find('dt'); //地址 $this->addr = ''; foreach ($a_dom_linfos as $dom_linfo) { if (mb_substr($dom_linfo->innertext, 0, 2, 'utf-8') == '价格') { $dom_price = $dom_linfo->next_sibling(); $this->price = $this->getNum4Text($dom_price->innertext); continue; } if (mb_substr($dom_linfo->innertext, 0, 2, 'utf-8') == '地区') { $dom_area = $dom_linfo->next_sibling(); $this->area = $dom_area->innertext; continue; } if (mb_substr($dom_linfo->innertext, 0, 2, 'utf-8') == '地址') { $dom_addr = $dom_linfo->next_sibling(); $this->addr = $dom_addr->innertext; continue; } } echo "this->price: {$this->price} <br/>"; echo "this->area: {$this->area} <br/>"; echo "this->addr: {$this->addr} <br/>"; $dom_info_right = $dom_info->find('div[class=r]', 0); $a_dom_rinfos = $dom_info_right->find('dt'); //联系人 $this->person = ''; foreach ($a_dom_rinfos as $dom_rinfo) { if (mb_substr($dom_rinfo->innertext, 0, 3, 'utf-8') == '联系人') { $dom_person = $dom_rinfo->next_sibling(); $this->person = $dom_person->innertext; continue; } if (mb_substr($dom_rinfo->innertext, 0, 2, 'utf-8') == '电话') { $dom_phone = $dom_rinfo->next_sibling(); $this->phone1 = $dom_phone->innertext; continue; } if (mb_substr($dom_rinfo->innertext, 0, 2, 'utf-8') == 'QQ') { $dom_phone = $dom_rinfo->next_sibling(); $this->qq = $dom_phone->innertext; continue; } if (mb_substr($dom_rinfo->innertext, 0, 2, 'utf-8') == '微信') { $dom_phone = $dom_rinfo->next_sibling(); $this->weixin = $dom_phone->innertext; continue; } if (mb_substr($dom_rinfo->innertext, 0, 4, 'utf-8') == '电子邮件') { $dom_phone = $dom_rinfo->next_sibling(); $this->email = $dom_phone->innertext; continue; } } echo "this->person: {$this->person} <br/>"; echo "this->phone1: {$this->phone1} <br/>"; echo "this->qq: {$this->qq} <br/>"; echo "this->weixin: {$this->weixin} <br/>"; //电子邮件 if (null != $this->email && $this->email != '') { $this->email = $this->getEMailByAJAX($this->vanpeople_id, $s_url); echo "this->email: {$this->email} <br/>"; } $dom_content = $dom_main->find('div[class=desc]', 0); //摘要 $this->enterprise = $a_config['desc']; //清理无用HTML $this->clearHTML($dom_content); //http://www.vanpeople.com/c/978680.html //保存图片路径并下载图片 $dom_content_pics = $dom_content->find('img[src^=http://vanpeople.com/c/uploadpic]'); $s_tmp_picpath = ''; foreach ($dom_content_pics as $dom_pic) { $s_src_picpath = $dom_pic->getAttribute('src'); $s_tmp_picpath = str_replace('vanpeople', 'www.vanpeople', $s_src_picpath); array_push($this->pics, $s_tmp_picpath); $dom_pic->parent()->outertext = ''; $s_path = $this->_dirBase . basename($s_tmp_picpath); array_push($this->picsLocal, $s_path); curl_download($s_tmp_picpath, $s_path); } echo 'img count : ' . count($this->pics) . '<br/>'; /* $dom_desc_title = $dom_content->find('p[class=mainBox_Ct]',0); $dom_desc_title->innertext = ''; $dom_desc_title->outertext = ''; */ //内容 $this->content = trim($dom_content->innertext); $html->clear(); echo '---------------------------------------------------<br/>'; return true; }
function curl_download($Url, $returnMode = 'stdout', $attempts = 0) { $attempts++; // is cURL installed yet? if (!function_exists('curl_init')) { die('Sorry cURL is not installed!'); } if ($returnMode == NULL) { $returnMode = 'string'; } $fileHandle = NULL; if ($returnMode != 'stdout' && $returnMode != 'string') { $dir = dirname($returnMode); if (!file_exists($dir)) { mkdir($dir, 0777, TRUE); } if (file_exists($returnMode) && $attempts == 1) { return '.<!--Exists - ' . $Url . ' => ' . $returnMode . '-->'; } else { $fileHandle = fopen($returnMode, 'w'); } } $ch = curl_init(); // Now set some options (most are optional) // Set URL to download curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer // curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm"); // User agent curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 PugpigNetwork"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, PUGPIG_CURL_TIMEOUT); if ($returnMode != 'stdout' && $returnMode != 'string') { curl_setopt($ch, CURLOPT_FILE, $fileHandle); curl_exec($ch); $error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); fclose($fileHandle); if ($error != '') { if ($attempts <= 5) { _fill_buffer(); _print_immediately('<!-- ' . $error . ' retrying...->'); return curl_download($Url, $returnMode, $attempts); } else { unlink($returnMode); return 'CURL ERROR: ' . $error . ' (' . $Url . ') [attempts: ' . $attempts . ']'; } } elseif ($http_code >= 400) { unlink($returnMode); return 'CURL HTTP ERROR ' . $http_code . ' (' . $Url . ')'; } else { return ($attempts == 1 ? '*' : $attempts) . '<!--OK - ' . $Url . ' => ' . $returnMode . '-->'; } } curl_setopt($ch, CURLOPT_HEADER, true); $output = curl_exec($ch); $error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($error != '') { if ($attempts < 5) { return curl_download($Url, $returnMode, $attempts); } else { return 'CURL ERROR: ' . $error . ' (' . $Url . ')'; } } elseif ($http_code >= 400) { return 'CURL HTTP ERROR ' . $http_code . ' (' . $Url . ') [attempts: ' . $attempts . ']'; } $headerend = strpos($output, "\r\n\r\n"); if ($headerend === false) { } else { $headers = explode("\r\n", substr($output, 0, $headerend)); $output = substr($output, $headerend + 4); } if ($returnMode == 'stdout') { //header_remove(); ob_end_clean(); ob_start(); if (isset($headers)) { foreach ($headers as $h) { if (strcasecmp(str_replace(' ', '', $h), 'transfer-encoding:chunked') == 0) { continue; } header($h); } } echo $output; exit; } elseif ($returnMode == 'string') { return $output; } else { return 'Unknown return method in curl_download: ' . $returnMode; } }
if (isset($_POST['Submit'])) { set_time_limit(0); echo $submitted_time = $_POST['year'] . '-' . $_POST['month'] . '-' . '01'; echo '<br />'; echo $timestamp = strtotime($submitted_time); echo '<br />'; include 'curl_scrape_events.php'; $stop = 1483383093; //Jan 2 2017 while ($timestamp < $stop) { $events_list_array = curl_download_first('http://visit-prescott.com/wordpress/calendar-2/?ai1ec=time_limit:' . $timestamp, 1); print_r($events_list_array); $timestamp = $timestamp + 1210000; // 2 weeks foreach ($events_list_array as $event) { print curl_download($event, 1); } echo '<strong>COMPLETED!!!!-----------------------------------------></strong>'; } } else { // If Not submitted ?> <?php global $network_admin, $form_action; $network_admin = 0; $form_action = 'http://localhost/sandbox/get-events/'; ?> <form name="export" action="<?php echo $_SERVER['PHP_SELF']; ?>
public function getInfo($base, $uri) { $linkWiki = $base . urldecode($uri); $content = file_get_contents($linkWiki); if (!$content) { echo '-x- Nieudana próba na ' . $linkWiki . '<br/>'; echo '-?- Próbuję odczytać cURLem na ' . $linkWiki . '<br/>'; $content = curl_download($linkWiki); if (!$content) { echo '-!- Pomijam ' . $linkWiki . '<br/>'; return false; } } $doc = new DOMDocument(); @$doc->loadHTML($content); $tds = $doc->getElementsByTagName('td'); unset($doc); $length = $tds->length; $nazwa = false; for ($i = 0; $i < $length; $i++) { $element = $tds->item($i); if ($element->hasAttribute('colspan') && $element->getAttribute('colspan') == 2) { $nazwa = $element; break; } } //mam nazwe miasta $nazwa = strip_tags($nazwa->ownerDocument->saveXml($nazwa)); echo $nazwa . '<br/>'; $doc = new DOMDocument(); @$doc->loadHTML($content); $spans = $doc->getElementsByTagName('span'); unset($doc); $length = $spans->length; $szerokosc = false; $dlugosc = false; for ($i = 0; $i < $length; $i++) { $item = $spans->item($i); if ($item->hasAttribute('class') && $item->getAttribute('class') == 'longitude') { $dlugosc = self::oczysc($item->ownerDocument->saveXml($item)); break; } } for ($i = 0; $i < $length; $i++) { $item = $spans->item($i); if ($item->hasAttribute('class') && $item->getAttribute('class') == 'latitude') { $szerokosc = self::oczysc($item->ownerDocument->saveXml($item)); break; } } $ludnosc = false; $doc = new DOMDocument(); $doc->loadHTML($content); $tds = $doc->getElementsByTagName('td'); unset($doc); $length = $tds->length; $tdWithLiczba = false; for ($i = 0; $i < $length; $i++) { $item = $tds->item($i); $html = htmlspecialchars($item->ownerDocument->saveXml($item)); $search = 'title="Liczba ludno'; if (strpos($html, $search) !== false) { $tdWithLiczba = $tds->item($i + 1); break; } } if ($tdWithLiczba) { $ludnosc = self::oczyscOproczCyfr($tdWithLiczba); } $array_to_return = array('nazwa' => $nazwa, 'szerokosc' => $szerokosc, 'dlugosc' => $dlugosc, 'ludnosc' => $ludnosc, 'link' => $linkWiki); // _d($array_to_return); return $array_to_return; }
if ($endIndex > 0) { $rfile = substr($rtext, $startIndex + 7, $endIndex - $startIndex - 3); //get real url from regexp $regex = '/userwork\\/([abc])(\\d+)\\/(\\w+)\\/(\\w+)\\.mp3/'; $matches = array(); if (preg_match($regex, $rfile, $matches)) { if (count($matches) > 4) { $e = base_convert($matches[2], 8, 10); $f = base_convert($matches[3], 16, 10) / $e / $e; $g = base_convert($matches[4], 16, 10) / $e / $e; if ($matches[1] == 'a' and $g % 1000.0 == $f) { $rfile = "http://a" . $e . "mp3.changba.com/userdata/userwork/" . $f . "/" . $g . ".mp3"; } } } curl_download($rfile, $lfile); echo 'name:' . $obj->songname . ' url:' . $rfile . "<br/>"; } } } if (file_exists($lfile)) { if (filesize($lfile) > 1024 * 3) { $jsObj = array(); $jsObj['title'] = $wtitle; $jsObj['url'] = $mp3url; array_push($allObjs, $jsObj); $hadNew = 1; } else { unlink($lfile); } }
<?php //$ID$ /** * @file * Custom Functions */ print curl_download('129.15.14.238/mdw/?q=node/2434'); //print curl_download('admin:sasdfs@129.15.14.238/mdw/?q=node/2422'); function curl_download($Url) { // is cURL installed yet? if (!function_exists('curl_init')) { die('Sorry cURL is not installed!'); } // OK cool - then let's create a new cURL resource handle $ch = curl_init(); // $options = array(CURLOPT_URL => $Url, // CURLOPT_HEADER => false, // CURLOPT_AUTOREFERER => 1, // CURLOPT_USERAGENT => "MozillaXYZ/1.0", // CURLOPT_RETURNTRANSFER => 1, // CURLOPT_TIMEOUT => 10, // CURLOPT_VERBOSE => 1); // Download the given URL, and return output curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm"); // User agent curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // Include header in result? (0 = yes, 1 = no)
function get_calendar_events($cal_url) { $events1 = curl_download($cal_url); $events2 = parse_output($events1); $events3 = parse_events($events2); $events4 = remove_colors($events3); $events5 = remove_whitespace($events4); $events6 = get_key_values($events5); get_json_cal_events($events6); }
function search($s, $lan) { $pgfound = ""; $aCount = 0; $aBestPgTxt = ""; $aBestPgPtr = ""; $aFound = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); switch ($lan) { case "de": $aPgURL = array('index.php', 'program.php', 'repertoire.php', 'teaching.php', 'kinder.php', 'meisterkurse.php', 'concert.php', 'video.php', 'presse.php', 'foto.php', 'bilde.php', 'bio.php', 'links.php', 'kontakt.php'); $aPgTitle = array('Homepage', 'Program', 'Repertoire', 'Untericht', 'Kinder', 'Meisterkurs', 'Konzerte', 'Video', 'Presse', 'Fotos', 'Shizzen', 'Biographie', 'Links', 'Kontakt'); $searchTitle = "Suche"; $notFound = "nicht gefunden"; $searchResults = "Suchergebnisse für"; break; case "ch": $aPgURL = array('index_ch.php', 'program_ch.php', 'repertoire_ch.php', 'teaching_ch.php', 'meisterkurse_ch.php', 'concert_ch.php', 'video_ch.php', 'presse_ch.php', 'foto_ch.php', 'bilde_ch.php', 'bio_ch.php', 'links_ch.php', 'kontakt_ch.php'); $aPgTitle = array('Homepage', 'Program', 'Repertoire', 'Untericht', 'Masterclass', 'Concerts', 'Video', 'Press', 'Photos', 'Sketches', 'Biography', 'Links', 'Contact'); $searchTitle = "搜"; $notFound = "未找到"; $searchResults = "搜索结果 "; break; default: $aPgURL = array('index_e.php', 'program_e.php', 'repertoire_e.php', 'teaching_e.php', 'meisterkurse_e.php', 'concert_e.php', 'video_e.php', 'presse_e.php', 'foto_e.php', 'bilde_e.php', 'bio_e.php', 'links_e.php', 'kontakt_e.php'); $aPgTitle = array('Homepage', 'Programme', 'Repertoire', 'Teaching', 'Masterclass', 'Concerts', 'Video', 'Press', 'Fotos', 'Sketches', 'Biography', 'Links', 'Contact'); $searchTitle = "Search"; $notFound = "not found"; $searchResults = "Search results for"; } for ($i = 0; $i < count($aPgTitle); $i++) { $url = $aPgURL[$i]; $pgtxt = curl_download("cuthbertson.de/" . $url); $startPos = strpos($pgtxt, "<body>"); $pgtxt = substr($pgtxt, $startPos); $pos = stripos(strtoupper($pgtxt), strtoupper($s)); if ($pos != false) { $aCount++; $aFound[$i] = 1; $aBestPgTxt = $pgtxt; $aBestPgPtr = $i; } } switch ($aCount) { case 0: print head($lan, $searchTitle, "index.php"); ?> <body> <div id="wrapper"> <div id="sidebar-wrapper"> <?php print menu($lan, $searchTitle); ?> </div> <div id="page-content-wrapper"> <div class="container-fluid"> <?php topRight(); ?> <div class="row"> <div class="col-lg-12"> <h2><?php print $searchTitle; ?> </h2> </div> </div> <div class="row"> <div class="col-lg-12"> <?php print "<br/>" . $s . " " . $notFound; ?> </div> </div> </div> </div> </div> </div> <!-- /#page-content-wrapper --> </div> <!-- /#wrapper --> </body> </html> <?php break; case 1: print $aBestPgTxt; break; default: print head($lan, $searchTitle, "search.php"); ?> <body> <div id="wrapper"> <div id="sidebar-wrapper"> <?php print menu($lan, $searchTitle); ?> </div> <div id="page-content-wrapper"> <div class="container-fluid"> <?php topRight(); ?> <div class="row"> <div class="col-lg-12"> <h2><?php print $searchTitle; ?> </h2> </div> </div> <div class="row"> <div class="col-lg-12"> <?php print $searchResults . " " . $s; print "<ul>"; for ($i = 0; $i < count($aPgTitle); $i++) { if ($aFound[$i] == 1) { print '<li><a href="' . $aPgURL[$i] . '">' . $aPgTitle[$i] . '</a></li>'; } } print "</ul>"; } ?> </div> </div> <?php print foot(); ?> </div> </div> </div> </div> <!-- /#page-content-wrapper --> </div> <!-- /#wrapper --> <?php print endPage(); ?> </body> </html> <?php }
// Retrieve and output the header to the page. echo curl_download($str_header_url); ?> <!-- Output some generic HTML text; this is the middle area between the consumed header and footer where you'd display site content. --> <p> Right here is where content is displayed, wrapped by the header and footer of this website. <br /><br /> The URL to the site header is: <a target="_blank" href="<?php echo $str_header_url; ?> "><?php echo $str_header_url; ?> </a> <br /> The URL to the site footer is: <a target="_blank" href="<?php echo $str_footer_url; ?> "><?php echo $str_footer_url; ?> </a> <br /><br /> Thanks for using the <b>External Header Footer</b> plug-in! Please write to <a href="mailto:sully@yllus.com">sully@yllus.com</a> if you encounter issues or have suggestions. </p> <?php // Retrieve and output the footer to the page. echo curl_download($str_footer_url);
function get_cop_events() { include 'scrape-events/curl_new_events.php'; //Check thru the ones that were previosly not displayed $not_displayed_posts = get_option('posts_not_displayed'); if (!empty($not_displayed_posts)) { //$not_displayed_posts = ''; //print_r($not_displayed_posts); $posts_not_displayed = ''; foreach ($not_displayed_posts as $not_displayed_post) { $post_id = $not_displayed_post; //echo '<br />ID: ' . $post_id; $url = 'http://www.prescott-az.gov/events/index.php?id=' . $post_id; $status = curl_download($url, $post_id); //print_r($status); if ($status[1] == true) { //echo $status[0] . ' was posted'; } if ($status[1] == false && !empty($status[0])) { //echo $status[0] . ' was NOT posted'; $posts_not_displayed[] = $status[0]; //print_r($posts_not_displayed); } } } if (empty($posts_not_displayed)) { $posts_not_displayed = array(); } $post_id = get_option('latest_event_id'); $post_id = $post_id + 1; $post_end = $post_id + 20; while ($post_id < $post_end) { if (in_array($post_id, $posts_not_displayed)) { $post_id++; continue; } //echo '<br />ID: ' . $post_id; $url = 'http://www.prescott-az.gov/events/index.php?id=' . $post_id; $status = curl_download($url, $post_id); //print_r($status); if ($status[1] == true) { //echo $status[0] . ' was posted'; } if ($status[1] == false && !empty($status[0])) { //echo $status[0] . ' was NOT posted'; $posts_not_displayed[] = $status[0]; //print_r($posts_not_displayed); } $post_id++; } //print_r($posts_not_displayed); update_option('posts_not_displayed', $posts_not_displayed); $file = 'people.txt'; // Open the file to get existing content $current = ''; // Append a new person to the file $current .= $post_id; // Write the contents back to the file file_put_contents($file, $current); $file = 'display.txt'; // Write the contents back to the file file_put_contents($file, $test_output); }
<?php $get_cookie_page = 'http://www.google.ca'; echo curl_download($get_cookie_page); function curl_download($Url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt'); $http_headers = array('Host: www.google.ca', 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', 'Accept: */*', 'Accept-Language: en-us,en;q=0.5', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Connection: keep-alive'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); return $output; }
/** * download images of an archive * @param Archive $archive */ protected function download_archive_images(Archive $archive) { $archive_start_at = microtime(true); $this->site->parse_archive($archive); $all_count = count($archive->images); $done_count = 0; $digit = strlen($all_count); $digit = $digit > 3 ? $digit : 3; $this->log('archive_start', date('Y-m-d H:i:s', $archive_start_at) . ' ' . $archive->id . " {$all_count} images start"); for ($i = 0; $i < $all_count; $i++) { if (PHP_OS == 'WINNT') { $title = iconv(strtoupper($archive->site->charset), strtoupper($GLOBALS['app_config']['win_charset']), $archive->title); } if ($archive->cover_mode) { $archive_folder = ''; $file_name = $archive->id . '_' . $title . '.' . get_file_ext($archive->images[$i]); // we need a shorter $file_id to write in log because $file_name would be too long sometimes. $file_id = $archive->id . '_.' . get_file_ext($archive->images[$i]); } else { $archive_folder = $archive->id . '_' . $title . '/'; $file_name = $archive->id . '_' . sprintf("%0{$digit}d", $i + 1) . '.' . get_file_ext($archive->images[$i]); $file_id = $file_name; } $save_path = ROOTPATH . 'storage/images/' . $this->config['save_folder'] . $archive_folder; mkdir_ex($save_path); $file = $save_path . $file_name; if (file_exists($file)) { $done_count++; continue; } // to do: detect file size & type $image_start_at = microtime(true); $result = curl_download($archive->images[$i], $file); $image_end_at = microtime(true); if ($result['status']['flag']) { $line = date('Y-m-d H:i:s', $image_end_at) . ' ' . $file_id . ' ok ' . sprintf('%.1fs', $image_end_at - $image_start_at); $this->log('image_done', $line); $done_count++; } else { unlink($file); $line = date('Y-m-d H:i:s', $image_end_at) . ' ' . $file_id . ' error ' . sprintf('%.1fs', $image_end_at - $image_start_at); $this->log('image_error', $line); } // usleep(mt_rand(200, 500)); } $archive_end_at = microtime(true); if ($done_count < $all_count) { $line = date('Y-m-d H:i:s', $archive_end_at) . ' ' . $archive->id . " {$done_count}/{$all_count}" . ' done(need redo) ' . sprintf('%.1fs', $archive_end_at - $archive_start_at); $this->log('archive_done', $line); return false; } else { $line = date('Y-m-d H:i:s', $archive_end_at) . ' ' . $archive->id . " {$done_count}/{$all_count}" . ' done ' . sprintf('%.1fs', $archive_end_at - $archive_start_at); $this->log('archive_done', $line); return true; } }
$base = intval(date('H', $tmNow)) % 12; $i = 0; while ($i < 2) { $tmNow = time() + ($base + $i * 12) * 3600 * 24; $strDate = date('Y-m-d', $tmNow); $link = 'http://apps.thomasluk.idv.hk/apps/themes/read_bible/' . date('Ymd', $tmNow) . 'p.mp3'; $lmp3 = './thought/mp3/' . date('Y-m-d', $tmNow) . '.mp3'; if (!file_exists($lmp3)) { $cxdate = date("Y-n-j", $tmNow); $cxradio = 'http://radio.cxsm.org/playlist/' . $cxdate . '.txt'; $cxlist = explode("\n", file_get_contents($cxradio)); //或是url list if (count($cxlist) > 1) { $link = cn_urlencode(trim($cxlist[1])); echo "Use cxradio mp3<br/>"; } echo "check link:" . $link . "<br/>"; if (url_exists($link)) { $bname = basename($link); echo "base name:" . $bname . '<br/>'; $local = './objs/' . time() . '_' . $bname; curl_download($link, $local); echo "download from:" . $link . "<br/>"; if (!rename($local, $lmp3)) { echo "rename false<br/>"; } } } $i++; } echo '<br/><h2>Done!!!</h2>';
<?php define('WP_USE_THEMES', false); require '../wp-blog-header.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $post_id = 45; $post_end = $post_id + 20; while ($post_id < $post_end) { $url = 'http://www.prescott-az.gov/public-notices/index.php?id=' . $post_id; print curl_download($url, $post_id); $post_id++; } function curl_download($Url, $post_id) { if (!function_exists('curl_init')) { die('cURL is not installed. Install and try again.'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); //curl_setopt($ch, CURLOPT_POST, TRUE); //curl_setopt($ch, CURLOPT_POSTFIELDS, array("searchId" => $sID)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $title = ''; $date = ''; $date_start = ''; $time_start = ''; $date_end = ''; $time_end = ''; $content = '';
function getQuote($url, $string) { require_once 'simple_html_dom.php'; $curl = curl_download($url); $html = str_get_html($curl); $all = $html->find('.yfi_rt_quote_summary_rt_top'); //Gets just the quote info ($all is for 'all' the quote info) $all = $all[0]; //Get each # seperately: $price = $all->find("[id^=yfs_l10_{$string}]"); $change = $all->find("[id^=yfs_c10_{$string}]"); $percentChange = $all->find("[id^=yfs_p20_{$string}]"); $date = $html->find('[id=yfs_market_time]'); //Remove HTML: $price = $price[0]->innertext; $change = $change[0]->innertext; $percentChange = $percentChange[0]->innertext; $change = preg_replace('/^.*?>\\s*/', '', $change); //Removes the updown image $date = $date[0]->innertext; $date = preg_replace('/EST.*/', 'EST', $date); //Removes the updown image return array($price, $date, $change, $percentChange); //return array($price, $date); }