To create a new DOMQuery, use QueryPath::with() or qp() function. If you are new to these documents, start at the QueryPath.php page. There you will find a quick guide to the tools contained in this project. A note on serialization: DOMQuery uses DOM classes internally, and those do not serialize well at all. In addition, DOMQuery may contain many extensions, and there is no guarantee that extensions can serialize. The moral of the story: Don't serialize DOMQuery.
See also: qp()
Inheritance: implements QueryPath\Query, implements IteratorAggregate, implements Countable
 /**
  * Write the title in the title tag of the page.
  */
 protected function renderTitle()
 {
     // Render page title
     if ($this->pageTitle != null) {
         $title = mb_convert_encoding($this->pageTitle, $this->getCharset(), 'auto');
         $this->qp->find("title")->append($title);
     }
 }
 /**
  * Write the title in the title tag of the page.
  */
 protected function renderTitle()
 {
     // Render page title
     if ($this->pageTitle != null) {
         $title = mb_convert_encoding($this->pageTitle, $this->getCharset(), 'auto');
         $domQuery = $this->qp->find("title");
         if ($domQuery->count() <= 0) {
             trigger_error('title tag not found in page', E_USER_WARNING);
         } else {
             $domQuery->append($title);
         }
     }
 }
示例#3
0
 /**
  * Attach any items from the list if they match the selector.
  *
  * If no selector is specified, this will remove all current matches from
  * the document.
  *
  * @param DOMQuery $dest
  *  A DOMQuery Selector.
  * @retval object DOMQuery
  *  The Query path wrapping a list of removed items.
  * @see replaceAll()
  * @see replaceWith()
  * @see removeChildren()
  * @since 2.1
  * @author eabrand
  */
 public function attach(DOMQuery $dest)
 {
     foreach ($this->last as $m) {
         $dest->append($m);
     }
     return $this;
 }
示例#4
0
 protected function GetAttributeFromElement(QueryPath\DOMQuery $Element, string $Query) : string
 {
     /*//
     	attempt to extract data from the specified attribute.
     	//*/
     switch ($Query) {
         case 'text':
             $DownloadURL = $Element->Text();
             break;
         default:
             $DownloadURL = $Element->Attr($Query);
             break;
     }
     return $DownloadURL;
 }
 /**
  * Extract a single value
  *
  * @param \QueryPath\DOMQuery $item
  * @param array $mapping
  * @param string $value
  * @return string
  */
 protected function _extractValue(\QueryPath\DOMQuery $item, array $mapping, $value = '')
 {
     if ($item) {
         if (!empty($mapping['attr'])) {
             $value = $item->attr($mapping['attr']);
         } elseif (!empty($mapping['innerHTML'])) {
             $value = $item->innerHTML();
         } else {
             $value = $item->text();
         }
     }
     $value = mb_convert_encoding($value, 'UTF-8', 'auto');
     if (!empty($mapping['preg'])) {
         if (preg_match($mapping['preg'], $value, $matches)) {
             $value = isset($matches[1]) ? $matches[1] : $matches[0];
         }
     }
     if (!empty($mapping['wrap'])) {
         $value = str_replace('|', $value, $mapping['wrap']);
     }
     if (!empty($mapping['strtotime'])) {
         $value = strtotime($value);
     }
     if (!isset($mapping['trim']) || !empty($mapping['trim'])) {
         $value = trim($value);
     }
     return $value;
 }
 /**
  *
  * @param DOMQuery $showtimesDomList
  * @param DOMQuery $movieDom
  * @return array
  */
 private function extractTimes($showtimesDomList, $movieDom)
 {
     $index = 0;
     $times = array();
     foreach ($showtimesDomList as $showtimesDom) {
         $getTicketsLink = $showtimesDom->find('a')->first();
         $showtimeTypeDom = new DOMQuery($movieDom->find('h5.li_group')->get($index++));
         $showtimeType = $showtimeTypeDom ? $this->getShowtimeType(trim($showtimeTypeDom->text(), ' :\\r\\n')) : 'digital';
         if ($getTicketsLink->length > 0) {
             $timeList = explode('|', $getTicketsLink->attr('data-times'));
             $link = $getTicketsLink->attr('href');
             foreach ($timeList as $movieTime) {
                 $times[] = array('show_date' => $this->currentDate, 'show_time' => $movieTime, 'url' => $link ? "{$link}+{$movieTime}" : '', 'type' => $showtimeType);
             }
         } else {
             $showtimes = trim(preg_replace('/\\s+/', ' ', $showtimesDom->text()));
             $showtimesArr = preg_split('/(\\|\\s*)+/', $showtimes);
             $lastAp = 'am';
             foreach ($showtimesArr as $timeThing) {
                 if (preg_match('/(am)|(pm)/i', $timeThing)) {
                     $tmp = explode(' ', $timeThing);
                     $lastAp = $tmp[1] ?: $lastAp;
                     $timeThing = $tmp[0];
                 }
                 $times[] = array('show_date' => $this->currentDate, 'show_time' => date('H:i:s', strtotime("{$timeThing} {$lastAp}")), 'type' => $showtimeType, 'url' => '');
             }
         }
     }
     return $times;
 }
 /**
  *
  * @param DOMQuery $movieDom
  * @return array
  */
 private function extractTimes($movieDom, $showtimeType)
 {
     $times = array();
     $showtimesDomList = $movieDom->find(".times > span");
     $lastAp = "";
     $replacePattern = ['/\\&[A-Za-z]+;?/', "/[^a-z0-9:]/"];
     for ($i = $showtimesDomList->length - 1; $i >= 0; $i--) {
         $stDom = new DOMQuery($showtimesDomList->get($i));
         $showtime = array();
         $timeSpan = preg_replace($replacePattern, "", trim($stDom->find("span")->first()->text()));
         $matches = array();
         if (preg_match("/(am)|(pm)/i", $timeSpan, $matches)) {
             $lastAp = $matches[0];
             $timeSpan = preg_replace("/(am)|(pm)/i", "", $timeSpan);
         }
         $actualTime = date('H:i:s', strtotime("{$timeSpan}{$lastAp}"));
         $showtime['show_date'] = $this->currentDate;
         $showtime['show_time'] = $actualTime;
         $showtime['type'] = $showtimeType;
         $ticketUrl = $stDom->find("a");
         if ($ticketUrl->length > 0) {
             $showtime['url'] = $this->extractUrl($ticketUrl->first()->attr('href'));
         } else {
             $showtime['url'] = "";
         }
         $times[] = $showtime;
     }
     return $times;
 }