Example #1
30
 public function scrap($username, $password)
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://studentinfo.bdu.edu.et/login.aspx');
     $form = $crawler->selectButton('Login')->form();
     $form['dnn$ctr$Login$Login_DNN$txtUsername'] = $username;
     $form['dnn$ctr$Login$Login_DNN$txtPassword'] = $password;
     $crawler = $client->submit($form);
     return $client->request('POST', 'MyGrades.aspx');
 }
Example #2
1
 /**
  * Add product data
  *
  * @param Crawler $node
  */
 private function addProduct(Crawler $node)
 {
     $product = new \stdClass();
     /** @var Crawler $title */
     $title = $node->filter('h3 a');
     $product->title = trim($title->text());
     $product->unit_price = $this->getPrice($node->filter('.pricePerUnit'));
     $productCrawler = $this->client->request('GET', $title->attr('href'));
     $product->size = $this->bytesToKb(strlen($this->client->getResponse()->getContent()));
     $product->description = '';
     $description = $productCrawler->filterXPath('//h3[.="Description"]');
     if ($description->count() > 0) {
         foreach ($description->siblings() as $sibling) {
             // product pages have different structures!
             if ($sibling->tagName == 'h3') {
                 break;
             }
             if ($product->description != "") {
                 $product->description .= "\n";
             }
             // @TODO address formatting issues - breaks to new lines
             $product->description .= trim(preg_replace("/[^\\S\r\n]+/", " ", $sibling->nodeValue));
             // remove excess whitespace but not new lines
         }
     }
     $this->total += $product->unit_price;
     // increment total
     $this->results[] = $product;
 }
Example #3
0
 /**
  * @param int $id
  *
  * @throws SubjectNotFoundException
  *
  * @return JusticeRecord|false
  */
 public function findById($id)
 {
     Assertion::integer($id);
     $crawler = $this->client->request('GET', sprintf(self::URL_SUBJECTS, $id));
     $detailUrl = $this->extractDetailUrlFromCrawler($crawler);
     if (false === $detailUrl) {
         return false;
     }
     $people = [];
     $crawler = $this->client->request('GET', $detailUrl);
     $crawler->filter('.aunp-content .div-table')->each(function (Crawler $table) use(&$people) {
         $title = $table->filter('.vr-hlavicka')->text();
         try {
             if ('jednatel: ' === $title) {
                 $person = JusticeJednatelPersonParser::parseFromDomCrawler($table);
                 $people[$person->getName()] = $person;
             } elseif ('Společník: ' === $title) {
                 $person = JusticeSpolecnikPersonParser::parseFromDomCrawler($table);
                 $people[$person->getName()] = $person;
             }
         } catch (\Exception $e) {
         }
     });
     return new JusticeRecord($people);
 }
 /**
  * Gets all shows and store them in json.
  */
 public function updateShows()
 {
     $url = $this->builder->getAddictedShowsUrl();
     printf("Trying to get shows from [%s].\n", $url);
     $crawler = $this->client->request('GET', $url);
     $showsLinkAndName = $crawler->filter('table.tabel90 > tr > td > h3 > a')->extract(['_text', 'href']);
     $showsSeasons = $crawler->filter('table.tabel90 > tr > td.newsDate')->extract(['_text']);
     if (count($showsLinkAndName) != count($showsSeasons)) {
         throw new \Exception("Inconsistencies detected while updating shows.");
     }
     printf("Found [%s] shows.\n", count($showsLinkAndName));
     $shows = [];
     foreach ($showsLinkAndName as $n => $show) {
         $id = $this->extractShowId($show[1]);
         if ($this->nonEmptyShow($showsSeasons[$n])) {
             $name = Episode::sanitizeShowName($show[0]);
             // if multiple shows name reference the same id
             if (isset($this->mappedShowsNames()[$name])) {
                 foreach ($this->mappedShowsNames()[$name] as $name) {
                     $shows[$name] = $id;
                 }
             } else {
                 $shows[$name] = $id;
             }
         }
     }
     $this->io->saveShows($shows);
 }
Example #5
0
 public function getCrawler()
 {
     if (!isset($this->crawler)) {
         $this->crawler = $this->client->request('GET', $this->getUri());
     }
     return $this->crawler;
 }
 public function testLoggedIn()
 {
     // we don't use the trait method here since we want our
     // test to span two page requests, and we need to have
     // the session persist on the remote server
     // create a web client and hit the login page
     $url = "http://localhost/login";
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $response_code = $client->getResponse()->getStatus();
     // we should get 200 back
     $this->assertEquals(200, $response_code);
     // select the form on the page and populate values
     // since we are using Goutte\Client, we don't need
     // to worry about parsing the HTML to find the csrf _token
     $form = $crawler->selectButton('Sign in')->form();
     $form->setValues(['email' => '*****@*****.**', 'password' => 'verysecret']);
     // submit the form
     $client->submit($form);
     $response_code_after_submit = $client->getResponse()->getStatus();
     // make sure the HTML page displayed (response code 200
     $this->assertEquals(200, $response_code_after_submit);
     // make sure we can get to the testimonial page
     $client->request('GET', 'http://localhost/add-testimonial');
     $response_code = $client->getResponse()->getStatus();
     $this->assertEquals(200, $response_code);
 }
Example #7
0
 /**
  * Extracts prices from HTML table.
  *
  * @param string $button Submit button text
  * @param array $location Region or county
  * @return array
  */
 protected function extractPricesFromTable($button, array $location)
 {
     $prices = [];
     $crawler = $this->client->request('GET', 'http://www.ccs.cz/pages/phm2.php');
     $form = $crawler->selectButton($button)->form();
     $crawler = $this->client->submit($form, $location);
     $columnIterator = 0;
     $rowIterator = 0;
     $crawler->filter('table[class="dynamic"] td')->each(function (DomCrawler $node) use(&$prices, &$columnIterator, &$rowIterator) {
         switch ($columnIterator) {
             case 0:
                 $prices[$rowIterator]['date'] = new \DateTime($node->text());
                 break;
             case 1:
                 $prices[$rowIterator]['natural95'] = $node->text();
                 break;
             case 3:
                 $prices[$rowIterator]['diesel'] = $node->text();
                 break;
         }
         $columnIterator = ++$columnIterator % 5;
         $rowIterator += $columnIterator == 0 ? 1 : 0;
     });
     return $prices;
 }
Example #8
0
 /**
  * Requests a URL.
  *
  * @param  string $url    The URL to request
  * @param  string $method The HTTP method
  * @return Crawler
  * @throws ConnectException
  */
 private function request($url, $method = 'GET')
 {
     try {
         return $this->client->request(strtoupper($method), $url);
     } catch (ConnectException $error) {
         throw $error;
     }
 }
Example #9
0
 /**
  * @param Url $url
  *
  * @return \Symfony\Component\DomCrawler\Crawler|null
  */
 public function scrape(Url $url)
 {
     try {
         return $this->client->request('GET', $url->getUrl());
     } catch (RequestException $e) {
         return;
     }
 }
Example #10
0
 private function scrap(Song $song)
 {
     $arr = [];
     $crawler = $this->client->request('GET', $song->url());
     $arr["title"] = $crawler->filter("title")->text();
     $arr["thumbnail_url"] = sprintf('http://img.youtube.com/vi/%s/1.jpg', $song->videoId());
     return $arr;
 }
 public function actionIndex()
 {
     /** @var $entity RivegaucheLink */
     $entity = new RivegaucheLink();
     $offset = 0;
     do {
         $links = $entity->getLinks($offset, 5);
         if (!empty($links)) {
             foreach ($links as $link) {
                 \Yii::info(sprintf('Обрабатываем: %s ', $link['link']), 'cron');
                 $client = new Client();
                 $guzzle = $client->getClient();
                 $client->getClient()->setDefaultOption('config/curl/' . CURLOPT_PROXY, 'http://141.101.118.147:80');
                 //$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 10);
                 $client->getClient()->setDefaultOption('config/curl/' . CURLOPT_CONNECTTIMEOUT, 10);
                 $client->setClient($guzzle);
                 /*$guzzle = $client->getClient();
                                     $guzzle->setDefaultOption('timeout', 10);
                 
                                     $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT_MS, 100);
                                     $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_CONNECTTIMEOUT, 5);
                                     $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_RETURNTRANSFER, true);
                                     $client->setClient($guzzle);*/
                 $crawler = $client->request('GET', $link['link']);
                 \Yii::info(sprintf('Извлекаем тело: %s ', $link['link']), 'cron');
                 $head = $this->getHtml($crawler, true);
                 \Yii::info(sprintf('HEAD тело: %s ', $link['link']), 'cron');
                 if (!empty($head['links'])) {
                     foreach ($head['links'] as $l) {
                         $crawler = $client->request('GET', $l);
                         $subHead = $this->getHtml($crawler, false);
                         $subHead['link'] = $l;
                         $this->saveResult($subHead, $link);
                     }
                 }
                 if (empty($head['title'])) {
                     $head = $this->getPromoHTML($crawler, true);
                 }
                 if (empty($head['title'])) {
                     $head = $this->getPromo2HTML($crawler, true);
                 }
                 $head['link'] = $link['link'];
                 $this->saveResult($head, $link);
                 unset($node);
                 unset($subNode);
                 unset($head);
             }
             $z = 1;
             $offset += 5;
             unset($links);
             unset($client);
         } else {
             $z = 0;
         }
     } while ($z > 0);
     return 0;
 }
 /**
  * Checks at the NABV site if the given card is correct
  * @param Card $card
  *
  * @return bool
  */
 public function isValidCard(Card $card)
 {
     $crawler = $this->client->request('POST', $this->url, ['relation_number' => $card->toString()]);
     $status = false;
     $crawler->filter('.alert.alert-success')->each(function () use(&$status) {
         $status = true;
     });
     return $status;
 }
 /**
  * Extract entries from given crawler object.
  *
  * @param \Symfony\Component\DomCrawler\Crawler $crawler
  * @return array
  */
 public function extractEntries(Crawler $crawler)
 {
     $links = $this->linksExtractor->extractEntries($crawler);
     $entries = array();
     if (count($links)) {
         foreach ($links as $link) {
             $entries[] = $this->entryExtractor->extractEntry($this->client->request('GET', $link));
         }
     }
     return $entries;
 }
Example #14
0
 /**
  * @param Client $client
  */
 public function request(Client $client)
 {
     if (isset($this->provider)) {
         $class = static::$providers[$this->provider];
         if (isset($class::$endpoint)) {
             $client->request('GET', $class::$endpoint . rawurlencode($this->url));
             $this->content = json_decode($client->getResponse()->getContent());
         } else {
             $this->content = $client->request('GET', $this->url);
         }
     }
 }
Example #15
0
 /**
  * その日に草が生えてるかをチェックする
  *
  * @param string $userName
  *
  * @return bool
  */
 public function checkContribution($userName)
 {
     // Getting user page souce
     $body = $this->goutteClient->request('GET', $this->getGitHubUrl($userName));
     // parse response body
     $contribution = null;
     $body->filter('rect')->last()->each(function ($name) {
         $contribution = $name->attr('fill');
     });
     // #eeeeeeはSaboってる
     return $contribution !== '#eeeeee';
 }
Example #16
0
 /**
  * Get the list of all available ads
  *
  * Returns an array of ads where one ad has the following format:
  *
  * array(7) {
  *     ["url"]=>
  *     string(52) "https://www.leboncoin.fr/velos/934826585.htm?ca=12_s"
  *     ["image"]=>
  *     string(81) "https://img1.leboncoin.fr/thumbs/010/010a091e6f370cf14f1bf446be768a92e6342d7f.jpg"
  *     ["title"]=>
  *     string(50) "Collier BBB 31.8mm ALU dérailleur avant à BRASER"
  *     ["category"]=>
  *     string(6) "Vélos"
  *     ["location"]=>
  *     string(33) "Carrières-sous-Poissy / Yvelines"
  *     ["price"]=>
  *     string(7) "10 €"
  *     ["date"]=>
  *     string(18) "Aujourd'hui, 14:12"
  * }
  *
  * @param srring    $url        the url that leads to search results
  * @param int       $maxAds     max number of ads to fetch (0 = gets all ads)
  *
  * @return array    $ads
  */
 public function getAds($url, $maxAds = 0)
 {
     $ads = [];
     $pageNumber = 1;
     $fetchedAds = 0;
     do {
         $crawler = $this->client->request('GET', $url, ['o' => $pageNumber]);
         $totalAds = str_replace(' ', '', $crawler->filter('#listingAds section header nav a')->first()->filter('span')->text());
         $nbAdsInPage = $crawler->filter('#listingAds > section > ul > li')->count();
         $ads += $this->_fetchAds($crawler, $fetchedAds, $maxAds);
         $fetchedAds += $nbAdsInPage;
         $pageNumber++;
     } while ($fetchedAds < $totalAds && ($maxAds == 0 || $fetchedAds < $maxAds));
     return array_slice($ads, 0, $maxAds ? $maxAds : count($ads));
 }
Example #17
0
 public function testUserSeesWelcomeMessage()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://tinkoff');
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertCount(1, $crawler->filter('h1:contains("Welcome to Tinkoff")'));
 }
Example #18
0
 protected static function fetchData(Client $client)
 {
     $page = $client->request('GET', 'http://www.movie.com.uy/teatro/');
     $premieres = self::getPlays($page->filter('div#proximos_est'));
     $billboard = self::getPlays($page->filter('div#cartelera_prin'));
     return array_merge(SpiderHelper::getPosterData($page), ['billboard' => array_merge($premieres, $billboard)]);
 }
Example #19
0
 private function parseURLPDF()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'https://www.pcfactory.cl/ventabodega');
     $href = $crawler->filter('a[class="main_link1"][href]')->first()->attr('href');
     return 'https://www.pcfactory.cl/' . $href;
 }
Example #20
0
 /**
  * Initializing the plugin's behavior
  *
  * @return void
  */
 public function init()
 {
     $that = $this;
     $this->bot->onMessages('/^!php(doc)? (.*)/i', function (Event $event) use($that) {
         $request = $event->getRequest();
         $matches = $event->getMatches();
         $match = array_pop($matches);
         $client = new Client();
         $crawler = $client->request('GET', sprintf('http://www.php.net/%s', str_replace('_', '-', $match)));
         if ($crawler->filter('.refnamediv h1.refname')->count() !== 0) {
             $function = $crawler->filter('.refnamediv h1.refname')->first()->text();
             $description = $crawler->filter('.refnamediv span.dc-title')->first()->text();
             $version = $crawler->filter('.refnamediv p.verinfo')->first()->text();
             $synopsis = $crawler->filter('.methodsynopsis')->first()->text();
             $synopsis = preg_replace('/\\s+/', ' ', $synopsis);
             $synopsis = preg_replace('/(\\r\\n|\\n|\\r)/m', ' ', $synopsis);
             $synopsis = trim($synopsis);
             $event->addResponse(Response::msg($request->getSource(), sprintf('%s - %s %s', $function, $description, $version)));
             $event->addResponse(Response::msg($request->getSource(), sprintf('Synopsis: %s', $synopsis)));
         } else {
             $suggestion = $crawler->filter('#quickref_functions li a b')->first()->text();
             $event->addResponse(Response::msg($request->getSource(), sprintf('Could not find the requested PHP function. Did you mean: %s?', $suggestion)));
         }
     });
 }
Example #21
0
 /**
  * simulate worldjournal ajax call to fetch content data
  */
 public function actionTrypostdata()
 {
     $hostname = 'www.wjlife.com';
     $optionVaules = ["relation" => "AND", "0" => ["relation" => "AND", "0" => ["key" => "wj_order_id"]]];
     //all help wanted
     $currentURL = "/cls_category/03-ny-help-wanted/";
     //temp page number
     $pno = 0;
     $queryObject = ["keyword" => "", "pagesize" => 40, "pno" => $pno, "optionVaules" => $optionVaules, "currentURL" => "http://" . $hostname . $currentURL, "currentCatId" => 327, "currentStateId" => 152];
     //language: chinese simplified
     $wjlang = "zh-cn";
     $requestUrl = "http://" . $hostname . "/wp-content/themes/wjlife/includes/classified-core.php?regions=state_ny&variant=" . $wjlang . "&t=" . time();
     // echo "start...\n";
     $client = new Client();
     $crawler = $client->request("POST", $requestUrl, $queryObject, [], ['HTTP_X-Requested-With' => 'XMLHttpRequest', 'contentType' => 'application/x-www-form-urlencoded;charset=utf-8']);
     $rowHtml = $crawler->html();
     // if you want to echo out with correct encoding, do `echo utf8_decode($rowHtml)`
     // echo utf8_decode($rowHtml);
     // echo "end...\n";
     $subCrawler = new Crawler();
     $subCrawler->addHtmlContent($rowHtml);
     $linkArray = $subCrawler->filter(".catDesc a")->each(function ($node, $index) {
         return $href = $node->attr('href');
     });
     print_r($linkArray);
 }
Example #22
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     for ($i = 68; $i <= 78; $i++) {
         //$photos=Image::paginate(50);
         $client = new Client();
         $baseURL = 'http://www.cutecatgifs.com/page';
         $urlEndpoint = '/' . $i++;
         $crawler = $client->request('GET', $baseURL . $urlEndpoint);
         $photos = $crawler->filter('img.alignnone')->extract(array('src', 'alt'));
         foreach ($photos as $photo) {
             $url = $photo[0];
             $title = $photo[1];
             $extension = pathinfo($url, PATHINFO_EXTENSION);
             $filename = str_random(4) . '-' . str_slug($title) . '.' . $extension;
             // get file content from url and save in directory
             $file = file_get_contents($url);
             $save_file = file_put_contents('uploads/' . $filename, $file);
             // Create record in database
             $image = new \App\Image();
             $image->name = $photo[1];
             $image->url = $filename;
             $image->user_id = 1;
             $image->description = $photo[1];
             $image->save();
         }
     }
 }
Example #23
0
 /**
  * Crawl single URL
  * @param string $url
  * @param int    $depth
  */
 protected function traverseSingle($url, $depth)
 {
     try {
         $client = new Client();
         $client->followRedirects();
         $crawler = $client->request('GET', $url);
         $statusCode = $client->getResponse()->getStatus();
         $hash = $this->getPathFromUrl($url);
         $this->links[$hash]['status_code'] = $statusCode;
         if ($statusCode === 200) {
             $content_type = $client->getResponse()->getHeader('Content-Type');
             if (strpos($content_type, 'text/html') !== false) {
                 //traverse children in case the response in HTML document only
                 $this->extractTitleInfo($crawler, $hash);
                 $childLinks = array();
                 if (isset($this->links[$hash]['external_link']) === true && $this->links[$hash]['external_link'] === false) {
                     $childLinks = $this->extractLinksInfo($crawler, $hash);
                 }
                 $this->links[$hash]['visited'] = true;
                 $this->traverseChildren($childLinks, $depth - 1);
             }
         }
     } catch (CurlException $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     } catch (\Exception $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     }
 }
Example #24
0
 public static function getHoje()
 {
     $nomes = ["Cantareira", "Guarapiranga", "Alto Cotia", "Alto Tietê", "Rio Claro", "Rio Grande"];
     $client = new Client();
     $crawler = $client->request('GET', 'http://www.apolo11.com/reservatorios.php?step=d');
     $tables = $crawler->filter("font[face='arial']");
     $data = $crawler->filter("font[face='verdana']");
     $obj = new stdClass();
     $obj->data = $data->eq(10)->text() . "/" . date('y');
     $obj->niveis = array();
     $tmp = array();
     for ($i = 0; $i < 6; $i++) {
         $nivel = new stdClass();
         $nivel->nome = $nomes[$i];
         $nivel->hoje = $tables->eq($i * 9 + 16)->text();
         $nivel->ontem = $tables->eq($i * 9 + 15)->text();
         $nivel->chuva = preg_replace("/[^0-9,.]/", "", $tables->eq(5 - $i)->text());
         $tmp[] = $nivel;
     }
     $obj->niveis[0] = $tmp[0];
     $obj->niveis[1] = $tmp[3];
     $obj->niveis[2] = $tmp[1];
     $obj->niveis[3] = $tmp[2];
     $obj->niveis[4] = $tmp[5];
     $obj->niveis[5] = $tmp[4];
     return $obj;
 }
Example #25
0
 /**
  * @param boolean $allPages
  */
 public function run($allPages)
 {
     $client = new Client();
     $client->getClient()->setDefaultOption('config/curl/' . CURLOPT_TIMEOUT, 30);
     $client->setHeader('User-Agent', $this->config['user_agent']);
     try {
         $crawler = $client->request('GET', $this->config['url']);
     } catch (TransferException $e) {
         echo $e->getMessage() . PHP_EOL;
         exit(1);
     }
     if ($client->getResponse()->getStatus() == 200) {
         $this->getUrlsAndDownload($crawler);
         if ($allPages) {
             $link = $this->getNextLink($crawler);
             while ($link) {
                 $crawler = $client->click($link);
                 $this->getUrlsAndDownload($crawler);
                 $link = $this->getNextLink($crawler);
             }
         }
     } else {
         echo "site not available\n";
     }
 }
 /**
  * Helper for submitting a message (post or private message)
  *
  * @param string $posting_url
  * @param string $posting_contains
  * @param array $form_data
  * @return \Symfony\Component\DomCrawler\Crawler the crawler object
  */
 protected function submit_message($posting_url, $posting_contains, $form_data)
 {
     if (time() == self::$last_post_timestamp) {
         // Travis is too fast, so we have to wait to not mix up the post/topic order
         sleep(1);
     }
     self::$last_post_timestamp = time();
     $crawler = self::request('GET', $posting_url);
     $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
     if (!empty($form_data['upload_files'])) {
         for ($i = 0; $i < $form_data['upload_files']; $i++) {
             $file = array('tmp_name' => __DIR__ . '/../functional/fixtures/files/valid.jpg', 'name' => 'valid.jpg', 'type' => 'image/jpeg', 'size' => filesize(__DIR__ . '/../functional/fixtures/files/valid.jpg'), 'error' => UPLOAD_ERR_OK);
             $crawler = self::$client->request('POST', $posting_url, array('add_file' => $this->lang('ADD_FILE')), array('fileupload' => $file));
         }
         unset($form_data['upload_files']);
     }
     $hidden_fields = array($crawler->filter('[type="hidden"]')->each(function ($node, $i) {
         return array('name' => $node->attr('name'), 'value' => $node->attr('value'));
     }));
     foreach ($hidden_fields as $fields) {
         foreach ($fields as $field) {
             $form_data[$field['name']] = $field['value'];
         }
     }
     // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
     // is not at least 2 seconds before submission, cancel the form
     $form_data['lastclick'] = 0;
     // I use a request because the form submission method does not allow you to send data that is not
     // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
     // Instead, I send it as a request with the submit button "post" set to true.
     return self::request('POST', $posting_url, $form_data);
 }
Example #27
0
 /**
  * 現在の株価を取得する
  *
  * @param 整数値 $code 取得する株価コード
  * @return bool true 成功
  */
 public function getStockPrice($code)
 {
     try {
         $client = new Client();
         $crawler = $client->request('GET', "http://stocks.finance.yahoo.co.jp/stocks/detail/?code={$code}.T");
         // 前日終値、始値、高値、安値を取得する
         $array = $crawler->filter('dd')->each(function ($element) {
             $array = $element->filter('strong')->each(function ($element) {
                 return $element->text();
             });
             // Debug::logPrintR($array);
             return count($array) > 0 ? $array[0] : null;
         });
         // Debug::logPrintR($array);
         // $array の要素は以下の様になっている
         // [2] 前日終値
         // [3] 始値
         // [4] 高値
         // [5] 安値
         if (count($array) >= 6) {
             $this->beforeClosingPrice = $this->removeComma($array[2]);
             $this->openingPrice = $this->removeComma($array[3]);
             $this->highPrice = $this->removeComma($array[4]);
             $this->lowPrice = $this->removeComma($array[5]);
         }
         // 現在値を取得する
         $element = $crawler->filter('td.stoksPrice')->last();
         $this->nowPrice = $this->removeComma($element->text());
     } catch (exception $e) {
         // Debug::logPrintR($e);
         return false;
     }
     return true;
 }
Example #28
0
function devtips_get($url)
{
    $tip = new DevTip(array("url" => $url));
    $client = new Client();
    $crawler = $client->request('GET', $url);
    $crawler->filter('div.dt-content')->each(function ($node) use(&$tip) {
        $html = trim($node->html());
        // add line breaks
        $html = str_replace("><", ">\n<", $html);
        // remove aside
        $pos = strpos($html, "<aside");
        if ($pos !== false) {
            $html = substr($html, 0, $pos);
        }
        // convert <p>'s to just line breaks
        $html = str_replace("<p>", "\n", $html);
        $html = str_replace("</p>", "\n", $html);
        $tip->set('content', $html);
    });
    $crawler->filter('h3')->each(function ($node) use(&$tip) {
        $tip->set('title', $node->text());
    });
    $sources = $crawler->filter('div.dt-content *[src]')->extract(array('src'));
    $tip->set('assets', $sources);
    return $tip;
}
Example #29
0
 /**
  * @param $url
  * @return Crawler
  */
 function getDataURL($url)
 {
     $client = new Client();
     $jsonURL = AlloSurfGetData::getJsonUrl($url);
     $crawler = $client->request('GET', $jsonURL);
     return $crawler;
 }
Example #30
-1
 /**
  * Obtém a lista de medicamentos do sistema da Anvisa e retorna um array
  * com os resultados.
  *
  * @param string $medicamento Nome de medicamento
  * @param string $empresa     Nome da fabricante do medicamento
  * @param string $expediente  Número do expediente da bula
  *
  * @throws \Exception Caso não for possível trazer os resultados
  *
  * @return \Collections\ArrayList Todas as bulas encontradas
  */
 public static function buscarMedicamentos($medicamento = '', $empresa = '', $expediente = '')
 {
     if (empty($medicamento) && empty($empresa) && empty($expediente)) {
         throw new \InvalidArgumentException('Informe pelo menos um parâmetro para o método!');
     }
     $Client = new Client();
     $crawler = $Client->request('POST', 'http://www.anvisa.gov.br/datavisa/fila_bula/frmResultado.asp', ['hddLetra' => '', 'txtMedicamento' => $medicamento, 'txtEmpresa' => $empresa, 'txtNuExpediente' => $expediente, 'txtDataPublicacaoI' => '', 'txtDataPublicacaoF' => '', 'txtPageSize' => '1000', 'btnPesquisar' => '']);
     $Medicamentos = new ArrayList();
     try {
         $trs = $crawler->filter('#tblResultado > tbody > tr');
         if ($trs->first()->filter('td')->count() > 1) {
             $trs->each(function ($node) use(&$Medicamentos) {
                 if (trim($node->filter('td')->eq(0)->text()) != 'Nenhuma bula na fila de análise') {
                     $nomeMedicamento = trim($node->filter('td')->eq(0)->text());
                     $nomeEmpresa = trim($node->filter('td')->eq(1)->text());
                     $exp = trim($node->filter('td')->eq(2)->text());
                     $dataPub = trim($node->filter('td')->eq(3)->text());
                     $dadosBulaPaciente = self::stripJsFunction($node->filter('td')->eq(4)->filter('a')->attr('onclick'));
                     $dadosBulaProfissional = self::stripJsFunction($node->filter('td')->eq(5)->filter('a')->attr('onclick'));
                     $Bula = new Bula();
                     $Bula->setMedicamento($nomeMedicamento);
                     $Bula->setEmpresa($nomeEmpresa);
                     $Bula->setExpediente($exp);
                     $Bula->setDataPublicacao($dataPub);
                     $Bula->setBulaPaciente(new DadosBula($dadosBulaPaciente['transacao'], $dadosBulaPaciente['anexo']));
                     $Bula->setBulaProfissional(new DadosBula($dadosBulaProfissional['transacao'], $dadosBulaProfissional['anexo']));
                     $Medicamentos->add($Bula);
                 }
             });
         }
     } catch (\Exception $ex) {
         throw new Exception('Houve um erro ao obter os medicamentos do sistema da Anvisa!');
     }
     return $Medicamentos;
 }