Chainable.
public static newDocumentFileHTML ( $file, $charset = null ) : phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery | ||
리턴 | phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery |
public function getManagerPage($errors = array()) { $html = phpQuery::newDocumentFileHTML(MVBAPK_HTML_DIR . 'admin/manager-page.html'); if ($_POST['submited']) { if (count($errors)) { $html['#notice-message > div:first']->removeClass('ui-state-highlight'); $html['#notice-message > div:first']->addClass('ui-state-error'); $html['#notice-message #message']->html(implode('<br/>', $errors)); } } else { $html['#notice-message']->addClass('dialog'); } //add list of styles $styles = $this->modelNode->getStyleList(); if (is_array($styles)) { foreach ($styles as $id => $style) { $id = esc_attr($id); $label = esc_js($style['label']); $html['#style']->append("<option value='{$id}'>{$label}</option>"); } reset($styles); $first = current($styles); $html['#current-style-display'] = $first['label']; } echo $html->htmlOuter(); }
public function finish() { phpQuery::newDocumentFileHTML($this->downloadUrl, $this->charset); $nodeCount = pq("#list2")->count(); $articleList = pq("#list2 tr"); echo "Start\n"; for ($i = 0; $i < $this->loop; $i++) { echo '='; } echo "\n"; $i = 0; foreach ($articleList as $tr) { $i++; if ($i <= 1) { # Filter the first node which has no meaning. continue; } $className = $tr->nodeValue; # This class order and its name. $classNameCombine = explode(' ', $className); $j = 0; $this->content[$i - 1]['chapterName'] = ''; foreach ($classNameCombine as $k => $v) { # Put all class order and its name into $this->content array. $v = trim($v); if (empty($v)) { continue; } $j++; if ($j == 1) { $this->content[$i - 1]['chapterId'] = $v; } else { $this->content[$i - 1]['chapterName'] .= $v . " "; } } $child = pq("td", $tr)->html(); $trueContent = explode(' ', $child); $linkString = ''; foreach ($trueContent as $k => $v) { $v = trim($v); if (empty($v)) { continue; } if ($v == "<a") { $linkString = $v . ' ' . $trueContent[$k + 1]; break; } } $urls = explode("\"", $linkString); $this->content[$i - 1]['link'] = $urls[1]; // $name = explode("<", $urls[2]); // $name = substr($name[0], 1); // $this->content[$i-1]['name'] = $name; } var_dump($this->content); for ($i = 0; $i < $this->loop; $i++) { echo '='; } echo "\nFinished! \n"; }
static function openUrl($url = null) { if ($url) { phpQuery::newDocumentFileHTML($url); } return true; }
public function getOffers() { $links = []; foreach ($this->pq->find('ul.a-pagination li a') as $pagerElem) { if (is_int($pagerElem['textContent'])) { continue; } $link = $pagerElem->attributes->getNamedItem('href')->value; if ($link == '#') { continue; } $links[] = $link; } $results = $this->getOffersFromPage(); foreach ($links as $link) { $this->pq = phpQuery::newDocumentFileHTML($link); $results = array_merge($results, $this->getOffersFromPage()); } return $results; }
/** * 测试采集内容 */ public function testpage() { header("Content-type: text/html; charset=utf-8"); //列表地址 $listurl = I('post.listurl'); $listurl = str_replace('{$page}', 2, $listurl); $urlInfo = parse_url($listurl); //解析列表 $listobj = $_POST['listobj']; //列表对象 $listattr = I('post.listattr'); //列表属性 //采集列表 Vendor('phpQuery.phpQuery', '', '.class.php'); \phpQuery::newDocumentFile($listurl); $artlist = pq($listobj); foreach ($artlist as $li) { $pageurl = pq($li)->attr($listattr); if (stripos($pageurl, 'http') !== 0) { $pageurl = $urlInfo['scheme'] . '://' . $urlInfo['host'] . $pageurl; } //采集内容 \phpQuery::$defaultCharset = I('post.langcode'); \phpQuery::newDocumentFileHTML($pageurl); //获取字段 $cate = I('post.cate'); $cateArr = explode(',', $cate); $mid = $cateArr[1]; $ModelField = DD('ModelField'); $fieldlist = $ModelField->selFieldByMid($mid); foreach ($fieldlist as $key => $f) { if (isset($_POST[$f['fieldname'] . '_rule'])) { $ruleJson = $_POST[$f['fieldname'] . '_rule']; $ruleObj = json_decode($ruleJson); if ($ruleObj->type == 0) { $artlist = pq($ruleObj->obj); echo $artlist->text() . '<br />'; } } } $artlist = pq($listobj); break; } }
print "<H4>" . _("Importing...") . "</H4>"; print "Tmpfile " . $filename . "<br>"; // DEBUG flush(); break; default: die_nicely("Unknown action {$action}"); } $fileType = $_POST["fileType"]; $history = $_POST["historyMode"]; $status = ""; $id_note = false; switch ($fileType) { case "FM": // Parse it $html = phpQuery::newDocumentFileHTML($uploadfile, 'ISO-8859-1'); if ($html['title']->text() != "FlightMemory - FlightData") { die_nicely(_("Sorry, the file {$uploadfile} does not appear contain FlightMemory FlightData.")); } // Table with padded cells has the data $rows = pq('table[cellspacing=2] tr[valign=top]')->elements; break; case "CSV": if ($action == _("Upload") && substr($_FILES["userfile"]["name"], -4) != ".csv") { die_nicely(_("Sorry, the filename must end in '.csv'.")); } $csvfile = fopen($uploadfile, "r"); if (!$csvfile) { die_nicely(_("Unable to open CSV file.")); } // Convert whole file into giant array
public function obtainHtml($caller_method, $template = null, $action = null, $add_html = array(), $partOnly = false) { //$caller_method = end(// explode('::',$caller_method)); if (strpos($caller_method, 'show') === false) { $vcsl = $VCSL = $caller_method; $with_form = false; } else { $VCSL = substr($caller_method, strlen('show')); $vcsl = strtolower($VCSL); $with_form = in_array($vcsl, $this->formMethods); } $overwrite_template = Main::$OVERWRITE_LAYOUT_TEMPLATES; if (empty($template)) { // get default path $template_file = $this->templateFilePath($VCSL); $template = file_exists($template_file) ? \phpQuery::newDocumentFileHTML($template_file) : ''; } else { if (file_exists($template)) { $template_file = $template; $template = \phpQuery::newDocumentFileHTML($template); } else { if (Main::hasNoHtmlTags($template)) { $template_file = $template; $template = ''; } else { // is an html snippet $template = \phpQuery::newDocument($template); $overwrite_template = false; } } } if (empty($template) or $overwrite_template) { if (empty($template_file)) { $template_file = $this->templateFilePath($VCSL); } $dom = \phpQuery::newDocumentFileHTML(Main::$MASTER_TEMPLATE); $dom['head']->append($this->getCSS($caller_method, 'html') . $this->getJS($caller_method, 'html')); foreach ($this->attributesTypes('\\SimplOn\\Datas\\File') as $fileData) { if ($fileData->{$vcsl}()) { $enctype = ' enctype="multipart/form-data" '; break; } } // create and fill file $html = ''; if ($with_form) { $html .= '<form class="' . $this->htmlClasses($vcsl) . '" ' . ' action="' . htmlentities(@$action ?: $this->encodeURL(Main::$construct_params, 'process' . $VCSL)) . '" ' . ' method="post" ' . @$enctype . '><fieldset><legend>' . $VCSL . ' ' . $this->getClassName() . '</legend>'; } $html .= '<div class="' . $this->htmlClasses() . '">'; foreach ($this as $keydata => $data) { if ($data instanceof Data && $data->hasMethod($vcsl) && $data->{$vcsl}()) { $html .= '<div class="' . $data->htmlClasses() . '">'; if ($with_form) { $data_id = 'SimplOn_' . $data->instanceId(); $dompart = \phpQuery::newDocumentHTML($data->{$caller_method}()); // @todo: Document that class input is MANDATORY $dompart['.reference']->attr('ref', $data_id); $dompart['.input']->attr('id', $data_id); $html .= $dompart; } else { $html .= $data->{$caller_method}(); } $html .= '</div>'; } } if ($with_form) { $html .= '<button type="submit">' . $VCSL . '</button>' . '<button class="SimplOn cancel-form">Cancel</button>' . '</div></fieldset></form>'; } else { $html .= '</div>'; } $dom['body'] = $html; // save file if (!empty($template_file)) { Main::createFile($template_file, $dom . ''); } } else { // opens file $dom = $template; } /** * @todo change the way HTL is filled instead of cicle triugh the datas * and filling the template cicle trough the template and run elment's * or data's methods as required. */ if ($with_form && $action) { $dom['form.SimplOn.Element.' . $this->getClassName()]->attr('action', $action); } foreach ($dom['.SimplOn.Data.SNL-' . $this->nestingLevel()] as $node) { $domNode = pq($node); $data = explode(' ', $domNode->attr('class')); if (!isset($data[4])) { $vladu = $domNode . ''; } if ($data[4]) { $data = $this->{'O' . $data[4]}(); if ($data instanceof Data && $data->hasMethod($caller_method)) { $domNode->html($data->{$caller_method}($domNode) ?: ''); } } } $dom['body']->prepend(@$add_html['header'] ?: '')->append(@$add_html['footer'] ?: ''); /* switch($partOnly) { case 0: case false: return $dom; case 1: case true: case 'element': return $dom[$this->cssSelector()]; default: return $dom[$partOnly]; }*/ if (!$partOnly) { return $dom; } else { if ($partOnly === true or $partOnly == 'element') { return $dom[$this->cssSelector()]; } else { return $dom[$partOnly]; } } }
<?php include 'header.php'; ?> <?php include 'nav.php'; ?> <div class="container"> <div class="row"> <div class="col col-lg-12 center-block"> <?php $html = 'http://www.dhmz.htnet.hr/prognoza/prognoze.php?id=pomorci'; $doc = phpQuery::newDocumentFileHTML($html); $table = pq("p:contains('VRIJEME NA JADRANU')")->next('table'); $data = array(); foreach ($table['td'] as $td) { $data[] = pq($td)->text(); } $data = array_chunk($data, 6); ?> <table class="table table-striped table-bordered" cellspacing="0" width="100%"> <thead> <tr class="bg-info"> <?php foreach ($data[0] as $title) { echo '<th>' . $title . '</th>'; } array_shift($data);
<?php require 'phpQuery/phpQuery.php'; $time_start = microtime(true); $total_page = 200; $page = 1; $header = array('', 'Rank', 'Team', 'Name', 'Point', 'Total'); echo "Page number, Time taken"; while ($page <= $total_page) { $doc = phpQuery::newDocumentFileHTML('http://fantasy.premierleague.com/my-leagues/303/standings/?ls-page=' . $page); foreach (pq('.ismStandingsTable tr') as $data) { foreach (pq('td', $data) as $key => $val) { if ($key == 2) { //print pq($val)->text(); } } } $time_end = microtime(true); $execution_time = $time_end - $time_start; echo "\n" . $page . ", " . $execution_time; $page++; }
public function getEntryByID($bID) { if (!$bID) { echo "No blog id set."; } else { if (!isset($this->Entries[$bID]) || !array_key_exists('fulltext', $this->Entries[$bID])) { $this->Entries[$bID]['url'] = $this->blogUrlBase . $bID; $blogEntryDom = \phpQuery::newDocumentFileHTML($this->Entries[$bID]['url'])->find('div.diary_flame'); $this->Entries[$bID]['id'] = $bID; $this->Entries[$bID]['headline'] = trim(pq('div.area_footer>h1:first', $blogEntryDom)->text()); $this->Entries[$bID]['tags'] = $this->_getTags(pq('div.diary_tag_body_w570', $blogEntryDom)); $this->Entries[$bID]['fulltext'] = $this->_getFulltext($blogEntryDom); // Shorttext is not really needed //$this->Entries[$bID]['shorttext'] = trim(pq('div.area_footer>h1:first',$blogEntryDom)->text()); } return $this->Entries[$bID]; } }
<?php require_once 'phpquery.php'; $file = 'http://www.nod325.com/'; // <div class="entry"> phpQuery::newDocumentFileHTML($file); $container = pq('.entry p:nth-of-type(3)'); echo $container->html(); // echo $sp=strip_tags($container);
$statement->bindParam(":title", $content["variation"]["title"], \PDO::PARAM_STR); $statement->bindParam(":content", $content["variation"]["content"], \PDO::PARAM_STR); $statement->execute(); $response = array('id' => (int) $pdo->lastInsertId()); echo json_encode($response); }); $app->get("/show/variation/:variation_id", function ($variationId) use($pdo) { // Load Variation Content; $statement = $pdo->prepare("\n SELECT st.ElementID, v.Content\n FROM variation AS v\n INNER JOIN splittest AS st ON v.SplitTest_ID = st.ID\n WHERE v.ID = :id\n "); $statement->bindParam(":id", $variationId, \PDO::PARAM_INT); $statement->execute(); $result = $statement->fetch(); if (!$result) { throw new \Exception("Variation '" . $variationId . "' not found."); } $doc = phpQuery::newDocumentFileHTML(__DIR__ . "/templates/coolblue-static.html"); $element = pq($result["ElementID"]); $element->html($result["Content"]); echo phpQuery::getDocument($doc->getDocumentID()); }); $app->get("/splittest", function () use($app, $twig, $pdo) { $app->request->get(""); }); $app->get("/external/:url", function ($url) { $style = '<link rel="stylesheet" href="/templates/lib/splittester/splittester.css" type="text/css"/>'; $js = '<script src="/templates/lib/jquery-modal/jquery.modal.min.js"></script>'; $js .= '<script src="/templates/lib/splittester/splittester.js"></script>'; $client = new GuzzleHttp\Client([]); $response = $client->request('GET', $url); $contentBody = $response->getBody(); $contentBody = preg_replace("/<head(.*?)>/", "<head\$1>{$style}", $contentBody);