/** * [getValue description] * @param object $dom объект DOMDocument() * @param string $classname название класса на странице * @param string $title название валюты */ function getValue(DOMDocument $dom, $classname, $title) { $finder = new DomXPath($dom); $div = $finder->query("//*[contains(@class, '{$classname}')]"); $val = $div->item(0)->textContent; echo $title . ' ' . substr($val, -5) . '<br>'; }
/** * @param string $accountNumber * @param int|null $maxItems * @param \DateTime|null $dateFrom * @param \DateTime|null $dateTo * @return \mixed[] */ public function getTransfers($accountNumber, $maxItems = null, DateTime $dateFrom = null, DateTime $dateTo = null) { $data = $this->getRawData($accountNumber, $dateFrom, $dateTo); $transferData = substr($data, strpos($data, '<table class=\'main\'>')); $transferData = substr($transferData, 0, strpos($transferData, '</table>') + 8); $dom = new \DOMDocument(); $dom->loadHTML($transferData); $finder = new \DomXPath($dom); $nodes = $finder->query('//table[@class="main"]//tbody//tr'); $transfers = array(); /** @var \DOMElement $node */ $i = 1; $length = $nodes->length; foreach ($nodes as $node) { $value = str_replace(',', '.', trim($node->childNodes->item(2)->nodeValue)); $value = (double) str_replace(' ', '', $value); $transfers[] = array(\DateTime::createFromFormat('d.m.Y', $node->childNodes->item(0)->nodeValue), $value, $node->childNodes->item(12)->nodeValue, $node->childNodes->item(14)->nodeValue); if ($maxItems !== null && $i >= $maxItems) { break; } $i++; if ($i >= $length) { break; } } $stateData = substr($data, strpos($data, '<table class=\'summary\'>')); $stateData = substr($stateData, 0, strpos($stateData, '</table>') + 8); $dom = new \DOMDocument(); $dom->loadHTML($stateData); $finder = new \DomXPath($dom); $nodes = $finder->query('//table[@class="summary"]//tbody//tr//td[2]'); $value = trim($nodes->item(0)->nodeValue); $value = str_replace(',', '.', $value); return array('state' => (double) str_replace(' ', '', $value), 'transfers' => $transfers); }
private static function _createBlockCode($code) { if (substr($code, 0, 5) == '<span') { $dom = new DomDocument(); $dom->loadXML($code); $xpath = new DomXPath($dom); $parentSpan = $xpath->query('/span')->item(0); $block_code = self::$_dom->createElement('fo:inline'); $block_code->setAttribute('color', substr($parentSpan->getAttributeNode('style')->value, 7, 7)); $nodes = $xpath->query('/span/node()'); foreach ($nodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE) { $child = self::$_dom->createElement('fo:inline', $node->nodeValue); $child->setAttribute('color', substr($node->getAttributeNode('style')->value, 7, 7)); } else { $child = self::$_dom->importNode($node, true); } $block_code->appendChild($child); } if (preg_match("/^\\s+\$/", $block_code->firstChild->textContent)) { $block_code->removeChild($block_code->firstChild); } } else { $block_code = self::$_dom->createElement('fo:inline', $code); } return $block_code; }
/** * Fetch and Parse a form for input fields * */ public function getInputs($type = 'text') { $content = preg_replace("/&(?!(?:apos|quot|[gl]t|amp);|#)/", '&', $this->source); $doc = new DOMDocument(); @$doc->loadHTML($content); $xpath = new DomXPath($doc); $list = array(); if ($type == 'text') { $items = $xpath->query('//form//input | //form//select | //form//textarea'); foreach ($items as $item) { if ($item->getAttribute('type') != 'submit' and $item->getAttribute('name') != 'Submit-button') { if ($item->getAttribute('type') != 'hidden') { $field = str_replace('[]', '', $this->has_attribute($item, 'name')); $field = trim($field); array_push($list, $field); } } } } elseif ($type == 'hidden') { $items = $xpath->query('//input | //select'); foreach ($items as $item) { if ($item->getAttribute('type') == 'hidden') { array_push($list, array('name' => trim($this->has_attribute($item, 'name')), 'value' => trim($this->has_attribute($item, 'value')))); } } } return $list; }
/** * * Enter description here ... * @param unknown_type $url */ public static function getProductComments($url) { header('Content-type: text/html; charset=utf-8'); $url = "http://ormatek.com/products/980"; $doc = file_get_contents($url); $doc = mb_convert_encoding($doc, 'HTML-ENTITIES', "UTF-8"); $query = ".//*[@class='comment']"; $dom = new DomDocument(); libxml_use_internal_errors(true); $dom->loadHTML($doc); $xpath = new DomXPath($dom); $nodes = $xpath->query($query); $i = 0; if (!is_array($nodes)) { return null; } foreach ($nodes as $node) { $name = $node->getElementsByTagName("b")->item(0)->nodeValue; $text = $node->getElementsByTagName("p")->item(0)->nodeValue; $date = $node->getElementsByTagName("span")->item(0)->nodeValue; $rating = 0; $i++; $param[] = array('id' => $i, 'name' => $name, 'date' => $date, 'rating' => $rating, 'text' => $text); } return $param; }
/** * Handle provided directory * * Optionally an existing result file can be provided * * If a valid file could be generated the file name is supposed to be * returned, otherwise return null. * * @param Project $project * @param string $existingResult * * @return string */ public function handle(Project $project, $existingResult = null) { if (!isset($project->analyzers['pdepend'])) { return; } $pdependResultFile = $project->dataDir . '/' . $project->analyzers['pdepend']; $document = new \DomDocument(); $document->load($pdependResultFile); $xPath = new \DomXPath($document); foreach ($xPath->query('//package') as $packageNode) { $packageCommits = 0; foreach ($xPath->query('./class', $packageNode) as $classNode) { $fileNode = $xPath->query('./file', $classNode)->item(0); $file = $fileNode->getAttribute('name'); $classCommits = $this->countGitChangesPerFileRange($project, $file, $classNode->getAttribute('start'), $classNode->getAttribute('end')); $packageCommits += $classCommits; $classNode->setAttribute('commits', $classCommits); foreach ($xPath->query('./method', $classNode) as $methodNode) { $methodCommits = $this->countGitChangesPerFileRange($project, $file, $methodNode->getAttribute('start'), $methodNode->getAttribute('end')); $methodNode->setAttribute('commits', $methodCommits); } } $packageNode->setAttribute('commits', $packageCommits); } $document->save($pdependResultFile); return null; }
/** * test processing of meeting reponse */ public function testMeetingResponse() { $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <MeetingResponse xmlns="uri:MeetingResponse" xmlns:Search="uri:Search"> <Request> <UserResponse>2</UserResponse> <CollectionId>17</CollectionId> <RequestId>f0c79775b6b44be446f91187e24566aa1c5d06ab</RequestId> </Request> <Request> <UserResponse>2</UserResponse> <Search:LongId>1129::64c542b3b4bf624630a1fbbc30d2375a3729b734</Search:LongId> </Request> </MeetingResponse> '); $meetingResponse = new Syncroton_Command_MeetingResponse($doc, $this->_device, null); $meetingResponse->handle(); $responseDoc = $meetingResponse->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('MeetingResponse', 'uri:MeetingResponse'); $nodes = $xpath->query('//MeetingResponse:MeetingResponse/MeetingResponse:Result'); $this->assertEquals(2, $nodes->length, $responseDoc->saveXML()); #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total'); #$this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); #$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result'); #$this->assertEquals(4, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
private function parse_search($html) { $doc = new DOMDocument(); @$doc->loadHTML($html); $finder = new DomXPath($doc); $torrents = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' hl-tr ')]"); $links = $finder->query("//*[contains(@class, 'med tLink hl-tags bold')]"); $result = array(); for ($i = 0; $i < $torrents->length; $i++) { $torrent = $torrents->item($i); $status = $this->clean($torrent->childNodes->item(2)->attributes->getNamedItem('title')->textContent); $category = $this->clean($torrent->childNodes->item(4)->textContent); $title = $this->clean($torrent->childNodes->item(6)->textContent); $torrent_id = (int) $this->clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent); $detail_url = "http://rutracker.org/forum/viewtopic.php?t={$torrent_id}"; $author_url = parse_url($torrent->childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent); $author_id = explode('=', $author_url['query']); $author_id = $author_id[1]; $author = array("id" => (int) $author_id, "name" => $this->clean($torrent->childNodes->item(8)->firstChild->firstChild->textContent)); $download_url = $this->clean($torrent->childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent); $size = $this->clean(str_replace(' ↓', '', $torrent->childNodes->item(10)->childNodes->item(3)->textContent)); $seeders = (int) $this->clean($torrent->childNodes->item(12)->firstChild->textContent); $leachers = (int) $this->clean($torrent->childNodes->item(14)->textContent); $downloads = (int) $this->clean($torrent->childNodes->item(16)->textContent); $added = date('d-m-Y', $this->clean($torrent->childNodes->item(18)->childNodes->item(1)->textContent)); $result[] = array("id" => $torrent_id, "title" => $title, "category" => $category, "status" => $status, "detail_url" => $detail_url, "author" => $author, "size" => $size, "download_url" => $download_url, "seeders" => $seeders, "leachers" => $leachers, "downloads" => $downloads, "added" => $added); } return $result; }
/** * test xml generation for IPhone */ public function testSearch() { $doc = new DOMDocument(); $doc->loadXML('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/"> <Search xmlns="uri:Search"> <Store> <Name>GAL</Name> <Query>Lars</Query> <Options> <Range>0-3</Range> <RebuildResults/> <DeepTraversal/> </Options> </Store> </Search> '); $search = new Syncroton_Command_Search($doc, $this->_device, null); $search->handle(); $responseDoc = $search->getResponse(); #$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('Search', 'uri:Search'); $nodes = $xpath->query('//Search:Search/Search:Status'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); $nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result'); $this->assertEquals(4, $nodes->length, $responseDoc->saveXML()); #$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
/** * @param string $html * @return TorrentsCollection */ public function parse(string $html) : TorrentsCollection { libxml_use_internal_errors(true); $doc = new \DOMDocument(); $doc->loadHTML($html); $finder = new \DomXPath($doc); $torrents = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' hl-tr ')]"); $links = $finder->query("//*[contains(@class, 'med tLink hl-tags bold')]"); $result = new TorrentsCollection(); for ($i = 0; $i < $torrents->length; $i++) { if (is_null($links->item($i))) { continue; } $childNodes = $torrents->item($i)->childNodes; $status = self::clean($childNodes->item(2)->attributes->getNamedItem('title')->textContent); $category = self::clean($childNodes->item(4)->textContent); $title = self::clean($childNodes->item(6)->textContent); $torrentId = (int) self::clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent); $detailUrl = self::DETAIL_URL . $torrentId; $authorUrl = parse_url($childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent); $authorId = (int) explode('=', $authorUrl['query'])[1]; $authorName = self::clean($childNodes->item(8)->firstChild->firstChild->textContent); $downloadUrl = self::clean($childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent); $downloadUrl = self::DOWNLOAD_URL . $downloadUrl; $size = self::clean(str_replace(' ↓', '', $childNodes->item(10)->childNodes->item(3)->textContent)); $seeders = (int) self::clean($childNodes->item(12)->firstChild->textContent); $leachers = (int) self::clean($childNodes->item(14)->textContent); $downloads = (int) self::clean($childNodes->item(16)->textContent); $added = (new \DateTimeImmutable())->setTimestamp((int) self::clean($childNodes->item(18)->childNodes->item(1)->textContent)); $torrent = (new Torrent())->setId($torrentId)->setTitle($title)->setCategory($category)->setStatus($status)->setDetailUrl($detailUrl)->setAuthorId($authorId)->setAuthorName($authorName)->setSize($size)->setDownloadUrl($downloadUrl)->setSeeders($seeders)->setLeachers($leachers)->setDownloads($downloads)->setAdded($added); $result->add($torrent); } return $result; }
function leistungsschutzrecht_fetchsites() { require_once "include/network.php"; $sites = array(); $url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html"; $site = fetch_url($url); $doc = new DOMDocument(); @$doc->loadHTML($site); $xpath = new DomXPath($doc); $list = $xpath->query("//td/a"); foreach ($list as $node) { $attr = array(); if ($node->attributes->length) { foreach ($node->attributes as $attribute) { $attr[$attribute->name] = $attribute->value; } } if (isset($attr["href"])) { $urldata = parse_url($attr["href"]); if (isset($urldata["host"]) and !isset($urldata["path"])) { $cleanedurlpart = explode("%", $urldata["host"]); $hostname = explode(".", $cleanedurlpart[0]); $site = $hostname[sizeof($hostname) - 2] . "." . $hostname[sizeof($hostname) - 1]; $sites[$site] = $site; } } } if (sizeof($sites)) { set_config('leistungsschutzrecht', 'sites', $sites); } }
/** * This function will return an associative array of all Glyphs equipped on the character. * * Associative Array Format: * "name" - Name of Glyph * "type" = Major, Minor, or Prime * "url" - URL of the Glyph * "itemNumber" - Unique item number of the Glyph. * * @return - An Associative Array. */ public function getGlyphs($character, $server) { $cacheFileName = Functions::getCacheDir().'talents_'.$character.'.html'; $contents = Functions::getPageContents($this->talentURLBuilder($character, $server), $cacheFileName); $dom = Functions::loadNewDom($contents); $xpath = new DomXPath($dom); $glyphTypes = array("major", "minor", "prime"); $glyphArray = array(); foreach($glyphTypes as $gT) { $glyphNames = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/span[@class="name"]'); $glyphLinks = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/@href'); $ctr = 0; foreach($glyphNames as $g) { $itemNumber = explode("/", $glyphLinks->item($ctr)->nodeValue); $tmpArray = array( "name" => trim(utf8_decode($g->nodeValue)), "type" => $gT, "url" => $glyphLinks->item($ctr)->nodeValue, "itemNumber" => $itemNumber[4] ); array_push($glyphArray, $tmpArray); $ctr++; } } return $glyphArray; }
function bold() { $this->CI =& get_instance(); $content = ""; $output = $this->CI->output->get_output(); $dom = new DOMDocument(); $dom->loadHTML($output); $finder = new DomXPath($dom); $classname = "lead"; $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]"); foreach ($nodes as $node) { $words = explode(' ', $node->nodeValue); $temp = $dom->createElement("p"); $temp->setAttribute("class", "lead"); foreach ($words as $word) { if (ctype_upper($word[0])) { //First char is uppercase $newNode = $dom->createElement('strong', $word . " "); $temp->appendChild($newNode); } else { $newNode = $dom->createTextNode($word . " "); $temp->appendChild($newNode); } } $node->parentNode->replaceChild($temp, $node); } echo $dom->saveHTML(); }
/** * Collects all translateable strings(from tags with 'trans' attribute) from html templates * * @param string $file absoulute path to file */ function extractFromHtml($file) { $dom = new DomDocument(); $dom->loadHTMLFile($file); $xpath = new DomXPath($dom); $nodes = $xpath->query("//*[@trans]"); foreach ($nodes as $i => $node) { // $info = "<{$node->tagName}> at $file"; $info = ""; if ($node->hasAttribute('context')) { $info = 'Context: ' . $node->getAttribute('context') . '. ' . $info; } if ($node->hasAttribute('placeholder')) { $this->addTranslationStr($node->getAttribute('placeholder'), $info); } if ($node->hasAttribute('title')) { $this->addTranslationStr($node->getAttribute('title'), $info); } if ($node->hasAttribute('data-intro')) { $this->addTranslationStr($node->getAttribute('data-intro'), $info); } if ($node->nodeValue != '' && $node->getAttribute('trans') != 'attr-only') { $this->addTranslationStr($node->nodeValue, $info); } } }
function getProducts() { include "../classes/httpFile.php"; include "../functions/crawler_functions.php"; error_reporting(E_ALL ^ E_WARNING); $http = new HttpConnection(); $http->setCookiePath("cookies/"); $http->init(); $DOM = new DOMDocument(); $url_array = split(PHP_EOL, file_get_contents('../file/cats_list.ccd')); while (count($url_array) > 0) { $url = array_shift($url_array); $http->get($url, true); get_dom($url, $DOM, $http); $finder = new DomXPath($DOM); $classname = "product-container"; $product = $finder->query("//*[contains( normalize-space( @class ), ' {$classname} ' )\r\n\t\t \t\t\tor substring( normalize-space( @class ), 1, string-length( '{$classname}' ) + 1 ) = '{$classname} '\r\n\t\t \t\t\tor substring( normalize-space( @class ), string-length( @class ) - string-length( '{$classname}' ) ) = ' {$classname}'\r\n\t\t \t\t\tor @class = '{$classname}']"); foreach ($product as $p) { $enlaces = $p->getElementsByTagName('a'); $enlace = $enlaces->item(0)->getAttribute('href'); echo $enlace . '<br/>'; file_put_contents("../file/url_list.ccd", $enlace . PHP_EOL, FILE_APPEND); } } $http->close(); }
protected function xpathQuery($html, $xpath) { $dom = new \DomDocument(); $dom->loadHtml($html); $domXpath = new \DomXPath($dom); return $domXpath->query($xpath); }
function DataAsHTML($xslFileName) { $xmlData = new SimpleXMLElement('<page/>'); $this->generateXML($xmlData, $this->data); $xmlfilemodule = simplexml_load_file("modules/" . $this->data['name'] . "/elements.xml"); $xmlData = dom_import_simplexml($xmlData)->ownerDocument; foreach (dom_import_simplexml($xmlfilemodule)->childNodes as $child) { $child = $xmlData->importNode($child, TRUE); $xmlData->documentElement->appendChild($child); } $xslfile = "templates/" . $this->template_name . "/" . $xslFileName . ".xsl"; $xslfilemodule = "modules/" . $this->data['name'] . "/elements.xsl"; if (in_array($this->data['name'], $this->selfPages)) { $xslfile = "templates/" . $this->template_name . "/" . $this->data['name'] . ".xsl"; } $domXSLobj = new DOMDocument(); $domXSLobj->load($xslfile); $xpath = new DomXPath($domXSLobj); $next = $xpath->query('//xsl:include'); $next = $next->item(0); $next->setAttribute('href', $xslfilemodule); $next->setAttribute('xml:base', ROOT_SYSTEM); $xsl = new XSLTProcessor(); $xsl->importStyleSheet($domXSLobj); return $xsl->transformToXml($xmlData); }
public function ovfImport($url, $xpath = false) { $this->url = $url; $dom = new DomDocument(); $loaded = $dom->load($url); if (!$loaded) { return $loaded; } $xpath = new DomXPath($dom); // register the namespace $xpath->registerNamespace('envl', 'http://schemas.dmtf.org/ovf/envelope/1'); $vs_nodes = $xpath->query('//envl:VirtualSystem'); // selects all name element $refs_nodes = $xpath->query('//envl:References'); // selects all name element $disk_nodes = $xpath->query('//envl:DiskSection'); // selects all name element $refs_nodes_0 = $refs_nodes->item(0); $disk_nodes_0 = $disk_nodes->item(0); $vs_nodes_0 = $vs_nodes->item(0); if ($refs_nodes_0 && $disk_nodes_0 && $vs_nodes_0) { $this->buildReferences($refs_nodes_0); $this->buildDiskSection($disk_nodes_0); $this->buildVirtualSystem($vs_nodes_0); return true; } else { return false; } }
/** * test testGetProperties method */ public function testGetProperties() { $body = '<?xml version="1.0" encoding="utf-8"?> <propfind xmlns="DAV:"> <prop> <getlastmodified xmlns="DAV:"/> <getcontentlength xmlns="DAV:"/> <resourcetype xmlns="DAV:"/> <getetag xmlns="DAV:"/> <id xmlns="http://owncloud.org/ns"/> </prop> </propfind>'; $request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName, 'HTTP_DEPTH' => '0')); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); //var_dump($this->response->body); $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status); $responseDoc = new DOMDocument(); $responseDoc->loadXML($this->response->body); //$responseDoc->formatOutput = true; echo $responseDoc->saveXML(); $xpath = new DomXPath($responseDoc); $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns'); $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id'); $this->assertEquals(1, $nodes->length, $responseDoc->saveXML()); $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML()); }
function getProducts() { $base_url = 'http://www.marcapl.com/marca/'; include "../classes/httpFile.php"; include "../functions/crawler_functions.php"; $http = new HttpConnection(); $http->init('galleta'); $DOM = new DOMDocument(); $url_array = explode(PHP_EOL, file_get_contents('../file/cats_list.ccd')); while (count($url_array) > 0) { $url = array_shift($url_array); if ($url == null || $url == " ") { echo "ENtrando"; continue; } //$url = 'http://www.marcapl.com/marca/index.php?seccion=productos&productos=listado&seccion1=Guantes%20de%20Trabajo&seccion2=Abrigo&i=0'; //$http->get(urlencode($url),false); get_dom($url, $DOM, $http); //$listado = $DOM->getElementById('listado_producto_referencia'); $finder = new DomXPath($DOM); $listado = $finder->query("//*[contains(@id, 'listado_producto_referencia')]"); foreach ($listado as $item) { $link = $item->getElementsByTagName('a'); $enlace = $link->item(0)->getAttribute('href'); if ($link != null) { file_put_contents("../file/url_list.ccd", $base_url . str_replace(" ", "%20", $enlace) . PHP_EOL, FILE_APPEND); } echo $enlace . '<br />'; } } $http->close(); }
/** * Checks Cardboard availability status. * * @return bool * Returns true if Cardboard is available. */ function cardboard_is_available() { $dom = new DOMDocument(); $html = @$dom->loadHTMLFile(CARDBOARD_URL); $classname = 'button-text'; $finder = new DomXPath($dom); $nodes = $finder->query("//*[contains(@class, '{$classname}')]"); return 'Not available' != $nodes->item(1)->textContent; }
public function xpath($path) { $xpath = new \DomXPath($this->dom); $list = $xpath->query($path); $return = []; foreach ($list as $node) { $return[] = $this->newElement($node); } return $return; }
/** * process the incoming data */ public function handle() { $xpath = new DomXPath($this->requestBody); $xpath->registerNamespace('2006', 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006'); $nodes = $xpath->query('//2006:Autodiscover/2006:Request/2006:EMailAddress'); if ($nodes->length === 0) { throw new Syncroton_Exception(); } $this->emailAddress = $nodes->item(0)->nodeValue; }
function printAppointmentsForLocations(DomXPath $xpath, $locations) { foreach ($locations as $location) { $appointmentCells = $xpath->query("descendant-or-self::*[@summary = 'Available appointments at " . $location . "']/tr/td"); if ($appointmentCells->length > 0) { echo $location . " appointments:\n"; printAppointments($appointmentCells); } } }
/** * get detail from product detail page * description and size of page * @param type $url * @return array */ private function getProductDescription($url) { $productDetail = array(); $doc = new DOMDocument(); $page = $this->httpRequest->getHTML($url); $doc->loadHTML($page['html']); $finder = new DomXPath($doc); $classname = "productText"; $nodes = $finder->query("//*[contains(@class, '{$classname}')]"); $productDetail['description'] = $nodes->item(0)->nodeValue; $productDetail['size'] = $this->changeSize($page['size']); return $productDetail; }
public function get_one_by_class($node, $class) { // $node é do tipo DomElement, precisa de um tipo DomDocument pra usar a classe DomXPath $tmp_dom = new \DOMDocument(); $tmp_dom->appendChild($tmp_dom->importNode($node, true)); $finder2 = new \DomXPath($tmp_dom); $nodes2 = $finder2->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$class} ')]"); foreach ($nodes2 as $node) { $firstNode = $node; break; } return $firstNode; }
function fetchShipsFromRSI($page) { error_log("fetching page " . $page); $memUrl = 'https://robertsspaceindustries.com/api/store/getShips'; $data = array('storefront' => 'pledge', 'pagesize' => '255', 'page' => $page); // use key 'http' even if you send the request to https://... $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data))); $context = stream_context_create($options); $result = file_get_contents($memUrl, false, $context); $var = json_decode($result, true); $str = $var["data"]["html"]; $ret = array(); if ($var["success"] != "1" || !strlen($str)) { return $ret; } error_log("------------ " . $var["success"] . " || " . strlen($str)); $DOM = new DOMDocument(); $DOM->loadHTML('<?xml encoding="utf-8" ?>' . $str); $xpath = new DomXPath($DOM); $items = $xpath->query('//li[@class="ship-item"]'); foreach ($items as $idx => $item) { $id = $xpath->query("@data-ship-id", $item); $divc = $xpath->query('./div[@class="center"]', $item)->item(0); $img = $xpath->query("./img/@src", $divc); $name = $xpath->query("./a[@class='filet']/span[contains(concat(' ', normalize-space(@class), ' '), name)]", $divc); $temp = split(' - ', $name->item(0)->nodeValue); $divb = $xpath->query("./div[contains(concat(' ', normalize-space(@class), ' '), bottom)]/span/span", $item); $imgm = $xpath->query("./div[contains(concat(' ', normalize-space(@class), ' '), bottom)]/span/img/@src", $item); $mname = basename($imgm->item(0)->value, ".png"); $shiparr = array("id" => $id->item(0)->value, "name" => $temp[0], "class" => $temp[1], "img" => "https://robertsspaceindustries.com" . $img->item(0)->value, "crew" => $divb->item(0)->nodeValue, "length" => $divb->item(1)->nodeValue, "mass" => $divb->item(2)->nodeValue, "mimg" => "https://robertsspaceindustries.com" . $imgm->item(0)->value, "mname" => $mname, "updated_at" => current_time('mysql')); array_push($ret, $shiparr); } return $ret; }
public function testBasicView() { $action = new CreateUserAction(); ok($action); $view = new ActionKit\View\StackView($action); ok($view); $html = $view->render(); ok($html); $resultDom = new DOMDocument(); $resultDom->loadXML($html); $finder = new DomXPath($resultDom); $nodes = $finder->query("//form"); is(1, $nodes->length); $nodes = $finder->query("//input"); is(4, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget')]"); is(8, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-widget-text')]"); is(2, $nodes->length); $nodes = $finder->query("//*[contains(@class, 'formkit-label')]"); is(3, $nodes->length); $nodes = $finder->query("//input[@name='last_name']"); is(1, $nodes->length); $nodes = $finder->query("//input[@name='first_name']"); is(1, $nodes->length); }
function handleJoinRequest($cookie, $group, $username, $choice, $save = 'hxcsrf.txt', $requestId = -1) { $xcsrf = file_exists($save) ? file_get_contents($save) : ''; $url = "http://www.roblox.com/My/GroupAdmin.aspx?gid={$group}"; switch ($choice) { case 'Accept': $choiceNumber = 1; break; case 'Decline': $choiceNumber = 2; break; default: die('Invalid choice.'); } if ($requestId === -1) { // This is so that if the function is being re called with the request ID already received you don't go through the whole process again (because it takes up a lot of time) $curl = curl_init($url); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie)); $response = curl_exec($curl); $nextPost = getPostArray(substr($response, curl_getinfo($curl, CURLINFO_HEADER_SIZE)), array('ctl00$ctl00$cphRoblox$cphMyRobloxContent$JoinRequestsSearchBox' => $username, 'ctl00$ctl00$cphRoblox$cphMyRobloxContent$JoinRequestsSearchButton' => 'Search')); curl_close($curl); $curl = curl_init($url); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $nextPost, CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie)); $response = curl_exec($curl); $doc = new DOMDocument(); $doc->loadHTML($response); $find = new DomXPath($doc); $nodes = $find->query("//span[contains(@class,'btn-control btn-control-medium accept-join-request')][1]"); foreach ($nodes as $node) { $requestId = $node->getAttribute('data-rbx-join-request'); } } $curl = curl_init('http://www.roblox.com/group/handle-join-request'); $post = array('groupJoinRequestId' => $requestId, 'accept' => $choiceNumber == 1 ? true : false); curl_setopt_array($curl, array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($post), CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array("X-CSRF-TOKEN: {$xcsrf}", 'Content-Length: ' . strlen(json_encode($post)), 'Content-Type: application/json; charset=UTF-8'), CURLOPT_COOKIEFILE => $cookie, CURLOPT_COOKIEJAR => $cookie, CURLOPT_RETURNTRANSFER => true)); $response = curl_exec($curl); $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($responseCode != 200) { if ($responseCode == 403) { // 403 XCSRF Token Validation Failed $header = http_parse_headers(substr($response, 0, $headerSize)); $xcsrf = $header['X-CSRF-TOKEN']; file_put_contents($save, $xcsrf); return handleJoinRequest($cookie, $group, $username, $choice, $save, $requestId); } } $text = $choiceNumber == 1 ? 'ed' : 'd'; return "{$choice}{$text} {$username}'s join request."; }
public static function exchange($amount, $from = 'NZD', $to = 'CNY') { $url = "http://www.google.com/finance/converter?a={$amount}&from={$from}&to={$to}"; if ($data = RPC::fetch($url)) { $dom = new \DOMDocument(); @$dom->loadHTML($data); $finder = new \DomXPath($dom); $classname = "bld"; $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]"); $node = $nodes->item(0)->nodeValue; $amount = str_replace(' CNY', '', $node); return number_format($amount, 2, '.', ','); } return false; }