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'); }
protected function login() { $page = $this->client->request('GET', 'http://fantasy.premierleague.com/'); $form = $page->selectButton('Log In')->form(); $this->client->submit($form, ['email' => Config::$username, 'password' => Config::$password, 'success' => 'http://fantasy.premierleague.com/accounts/login/', 'fail' => 'http://fantasy.premierleague.com/?fail']); $this->is_logged_in = true; }
public function getByDate() { $client = new Client(); //$client->getClient()->setDefaultOption('config/curl/' . CURLOPT_SSL_VERIFYPEER, false); $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false))); $client->setClient($guzzleClient); $crawler = $client->request('GET', 'https://portalcfdi.facturaelectronica.sat.gob.mx/'); $form = $crawler->filterXPath('//form')->form(); $crawler = $client->submit($form); $link = $crawler->selectLink('Contraseña')->link(); $crawler = $client->request('GET', $link->getUri()); $form = $crawler->selectButton('Enviar')->form(); $form['Ecom_User_ID'] = 'GRI081024694'; $form['Ecom_Password'] = '******'; $crawler = $client->submit($form); $form = $crawler->filterXPath('//form')->form(); $crawler = $client->submit($form); $form = $crawler->filterXPath('//form')->first()->form(); $crawler = $client->submit($form); $form = $crawler->filterXPath('//form')->first()->form(); $form['wresult'] = preg_replace('/\\s+/', '', $form->getValues()['wresult']); //dd(preg_replace('/\s+/', '', $form->getValues()['wresult'])); $crawler = $client->submit($form); echo $crawler->html(); //dd($crawler->html()); //dd($form->getValues()['wresult']); }
/** * 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; }
protected function authenticateClient() { $crawler = $this->authenticatedClient->request('GET', $this->baseUrl . $this->loginPath); $form = $crawler->selectButton($this->submitButtonText)->form(); $crawler = $this->authenticatedClient->submit($form, [$this->usernameField => $this->user['identifier'], $this->passwordField => $this->user['password']]); $this->assertEquals($this->loggedInLinkText, $crawler->selectLink($this->loggedInLinkText)->text()); $this->printLn(sprintf('Authenticating with user %s wth role %s was Ok', $this->user['identifier'], $this->user['role'])); }
public function ensureLoggedIn() { $crawler = $this->client->request('GET', '/user/login'); /** @var Response $response */ $response = $this->client->getResponse(); if ($response->getStatus() < 200 && $response->getStatus() >= 300) { return; } $loginForm = $crawler->filter('#loginPageForm')->form(); $this->client->submit($loginForm, ['username' => $this->username, 'password' => $this->password]); if (strpos($this->client->getHistory()->current()->getUri(), 'account') === FALSE) { throw new \PHPUnit_Framework_Exception("Should be logged in, but is not."); } }
protected function execute(InputInterface $input, OutputInterface $output) { $licence = $input->getArgument('licence'); $center = $input->getArgument('center'); $filterDate = $input->getOption('filter'); $mail = $input->getOption('mail'); $client = new Client(); $crawler = $client->request('GET', 'https://driverpracticaltest.direct.gov.uk/application'); $output->writeln('Step 1'); $form = $crawler->selectButton('testTypeCar')->form(); $crawler = $client->submit($form); $output->writeln('Step 2'); $form = $crawler->selectButton('drivingLicenceSubmit')->form(); $form->setValues(['driverLicenceNumber' => $licence, 'extendedTest' => 'false', 'specialNeeds' => 'false']); $crawler = $client->submit($form); $output->writeln('Step 3'); $form = $crawler->selectButton('testCentreSubmit')->form(); $form->setValues(['testCentreName' => $center]); $crawler = $client->submit($form); $output->writeln('Step 4'); $link = $crawler->filter('.test-centre-results > li > a')->first()->link(); $crawler = $client->click($link); $output->writeln('Step 5'); $button = $crawler->selectButton('drivingLicenceSubmit'); if ($button->count() == 0) { $output->writeln('Captcha!'); //TODO: display captcha image and ask to solve? Use decaptcha? return; } $form = $button->form(); $date = (new \DateTime())->format('d/m/y'); $form->setValues(['preferredTestDate' => $date]); $crawler = $client->submit($form); $output->writeln('Step 6'); $slots = $crawler->filter('.slotDateTime'); $dates = $slots->each(function ($node, $i) use($output) { return $node->text(); }); if ($filterDate) { $filter = new DateFilter(); $dates = $filter->filterDates($dates, $filterDate); } foreach ($dates as $date) { $output->writeln($date); } if (count($dates) && $mail) { $mailer = new DateMailer(); $mailer->mail($mail, $dates); } }
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); }
/** * Submits a form * * @param Symfony\Component\DomCrawler\Form $form A Form instance * @param array $values An array of form field values * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ public static function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { $crawler = self::$client->submit($form, $values); if ($assert_response_html) { self::assert_response_html(); } return $crawler; }
/** * Execute load request. * * @return array */ public function execute() { $client = new Client(); $client->getClient()->setDefaultOption('verify', false); $crawler = $client->request('GET', 'https://loadxtreme.ph/cgi-bin/webload.cgi?state=webload'); $form = $crawler->selectButton('SEND LOAD')->form(); $crawler = $client->submit($form, array('state' => 'webload', 'step' => '1', 'webtype' => '', 'uid' => $this->uid, 'pik' => $this->pik, 'pc' => $this->pc, 'cellno' => $this->cellno, 'email' => $this->email)); return $this->response($crawler->html()); }
public function check() { $client = new Client(); $crawler = $client->request('GET', 'http://www.abxexpress.com.my'); $trackBtn = $crawler->selectButton('Track'); $form = $trackBtn->form(); $crawler = $client->submit($form, array('tairbillno' => $this->tracking_no)); return $crawler->html(); }
/** * @group liveTest */ public function testRequestHostedEndpointLive() { $requestDTO = $this->generatePaymentRequestDTO(); $response = $this->giropayHostedService->requestHostedEndpoint($requestDTO); $this->assertInstanceOf("PHPCommerce\\Payment\\Dto\\PaymentResponseDTO", $response); $redirectUrl = $response->getResponseMap()[GiropayConstants::HOSTED_REDIRECT_URL]; $client = new Client(); $crawler = $client->request('GET', $redirectUrl); //bank login screen, login with test data $this->assertEquals(200, $client->getResponse()->getStatus()); $this->assertContains("Online-Banking: Anmelden", $client->getResponse()->__toString()); $form = $crawler->selectButton('Sicher anmelden')->form(); $crawler = $client->submit($form, array('account/addition[@name=benutzerkennung]' => 'sepatest1', 'ticket/pin' => '12345')); // //validation screen, just click next button $this->assertEquals(200, $client->getResponse()->getStatus()); $this->assertContains("Bitte wählen Sie eine Mobilfunknummer für den smsTAN-Versand", $client->getResponse()->__toString()); $form = $crawler->selectButton('weiterButton')->form(); $crawler = $client->submit($form, array()); // //tan screen, enter tan $this->assertEquals(200, $client->getResponse()->getStatus()); $this->assertContains("Bitte kontrollieren Sie vor der Eingabe der TAN die per SMS versandten Auftragsdaten", $client->getResponse()->__toString()); $form = $crawler->selectButton('absendenButton')->form(); $crawler = $client->submit($form, array('ticket/tan' => '123456')); // //success screen $this->assertEquals(200, $client->getResponse()->getStatus()); $this->assertContains("Der Auftrag wurde entgegengenommen", $client->getResponse()->getContent()->__toString()); $form = $crawler->selectButton('back2MerchantButton')->form(); $crawler = $client->submit($form, array()); // //redirect screen $this->assertEquals(200, $client->getResponse()->getStatus()); $this->assertContains("Die Rücksprungadresse zum Händler wird ermittelt", $client->getResponse()->getContent()->__toString()); //wait until the redirect address is populated sleep(3); $client->followRedirects(false); $form = $crawler->selectButton('go')->form(); $crawler = $client->submit($form, array()); $redirectUrl = $client->getResponse()->getHeader('Location'); // }
function obtener_info_cursos($idCarrera) { $client = new Client(); //Obtengo creditos y validez del curso $crawler = $client->request('GET', "http://www1.bedelias.edu.uy/ingenieria/muestra_mats.impr?car={$idCarrera}"); //Obtengo las tablas por área, y almaceno los cursos de cada una $crawler->filter('.unoa')->each(function ($node, $index) use($idCarrera) { if ($index == 0) { return; } //De la tabla obtengo la informacion de los cursos $datos_cursos = leer_tabla($node); //Almaceno creditos y validez foreach ($datos_cursos as $datos_curso) { try { guardar_creditos_validez($datos_curso[0], $datos_curso[1], $datos_curso[2]); } catch (Exception $e) { echo $e->getMessage(); } } }); //Obtengo porcentajes de aprobacion $crawler = $client->request('GET', "http://www1.bedelias.edu.uy/ingenieria/actas_curso.sel_per_car"); //Obtengo los meses y obtengo los datos para cada periodo $crawler->filter('select[name="p_permes"] option')->each(function ($node, $index) use($crawler, $client, $idCarrera) { $form = $crawler->selectButton('Aceptar')->form(); $actas_mes = $client->submit($form, array('p_permes' => $node->text(), "p_curri" => "C", "p_carrcic" => $idCarrera)); //Por cada curso del periodo obtengo los datos $actas_mes->filter('select[name="p_matnommat"] option')->each(function ($node, $index) use($actas_mes, $client) { $form = $actas_mes->selectButton('Aceptar')->form(); $datos_curso = explode(" - ", $node->html()); $id_curso = trim($datos_curso[0]); $acta_curso = $client->submit($form, array('p_matnommat' => $id_curso)); $datos = obtener_datos_aprobacion($acta_curso); try { //guardar_datos_aprobacion($id_curso, $datos); } catch (Exception $e) { echo $e->getMessage(); } }); }); }
protected function execute(InputInterface $input, OutputInterface $output) { $licence = $input->getArgument('licence'); $reference = $input->getArgument('reference'); $filterDate = $input->getOption('filter'); $mail = $input->getOption('mail'); $client = new Client(); $crawler = $client->request('GET', 'https://driverpracticaltest.direct.gov.uk/login'); $output->writeln('Step 1'); $form = $crawler->selectButton('booking-login')->form(); $form->setValues(['username' => $licence, 'password' => $reference]); $crawler = $client->submit($form); $output->writeln('Step 2'); $link = $crawler->filter('#date-time-change')->first()->link(); $crawler = $client->click($link); $output->writeln('Step 3'); $button = $crawler->selectButton('drivingLicenceSubmit'); if ($button->count() == 0) { $output->writeln('Captcha!'); //TODO: display captcha image and ask to solve? Use decaptcha? return; } $form = $button->form(); $crawler = $client->submit($form); $output->writeln('Step 4'); $slots = $crawler->filter('.slotDateTime'); $dates = $slots->each(function ($node, $i) use($output) { return $node->text(); }); if ($filterDate) { $filter = new DateFilter(); $dates = $filter->filterDates($dates, $filterDate); } foreach ($dates as $date) { $output->writeln($date); } if (count($dates) && $mail) { $mailer = new DateMailer(); $mailer->mail($mail, $dates); } }
public static function authenticate() { $client = new Client(); $crawler = $client->request('GET', Conf::DOMAIN . "/"); // select the form and fill in some values $form = $crawler->filter('body > div > form')->form(); $form['email'] = Conf::EMAIL; $form['password'] = Conf::PASS; // submit that form $crawler = $client->submit($form); return $client; }
public function testSubmitFormDisplaysNewValues() { $client = new Client(); $crawler = $client->request('GET', 'http://localhost'); $form = $crawler->selectButton('OK')->form(); $formValues = array('people[0][firstname]' => 'Leslie', 'people[0][surname]' => 'Winkle'); $crawler = $client->submit($form, $formValues); $form = $crawler->selectButton('OK')->form(); $values = $form->getValues(); $this->assertEquals('Leslie', $values['people[0][firstname]']); $this->assertEquals('Winkle', $values['people[0][surname]']); }
/** * @param $testId * @param int $operationId * @param array $testData * @return array */ public function run($testId, $operationId = 0, $testData = []) { //$opData = $testData['operations'][$operationId]; $orderId = $testData['orderId']; // Log in $crawler = $this->client->request('GET', $this->host . '/user/login'); $loginFormNode = $crawler->filter('#loginPageForm'); $loginForm = $loginFormNode->form(); $this->client->submit($loginForm, ['username' => $this->username, 'password' => $this->password]); // Find a page with transaction form and submit it (override in subclasses) $crawler = $this->submitTransactionForm($orderId); //var_dump($this->client->getHistory(), parse_url($this->client->getHistory()->current()->getUri())); exit; // Go home $homeForm = $crawler->filter('form')->first()->form(); $result = ['ACTION' => $homeForm->get('ACTION')->getValue(), 'RC' => $homeForm->get('RC')->getValue(), 'TRTYPE' => $homeForm->get('TRTYPE')->getValue(), 'RRN' => $homeForm->get('RRN')->getValue(), 'operation' => $operationId, 'test' => $testId, 'ORDER' => $homeForm->get('ORDER')->getValue(), 'date' => date('m/d/Y')]; $this->client->submit($homeForm); ob_start(); var_dump($this->client->getHistory()); $result['history'] = ob_get_clean(); return $result; }
/** * Does login with ID and access key. **/ public function doResponsavelLogin() { // get csrf token $this->crawler = $this->client->request('GET', $this->responsavel_endpoint); $token = $this->crawler->filter('input[name="csrfmiddlewaretoken"]'); $token = $token->attr('value'); // get form and submit $form = $this->crawler->selectButton('Acessar')->form(); $this->crawler = $this->client->submit($form, ['matricula' => $this->username, 'chave' => $this->password, 'csrfmiddlewaretoken' => $token]); // set matricula $info = $this->crawler->filter('table[class="info"]'); $this->matricula = trim($info->filter('td')->eq(5)->text()); }
<?php /* * * Ejemplo para obtener las previas del curso de logica * */ require_once 'goutte.phar'; use Goutte\Client; $client = new Client(); // Pagina de previas $crawler = $client->request('GET', 'http://www1.bedelias.edu.uy/ingenieria/muestra_prev.selcarr'); // Obtengo el boton del formulario $form = $crawler->selectButton('Aceptar')->form(); // Envio el formulario con la carrera de Ing en computación seleccionada $crawler = $client->submit($form, array('car' => '7200')); // Obtengo el boton del formulario $form = $crawler->selectButton('Aceptar')->form(); // Selecciono el curso de Lógica $crawler = $client->submit($form, array('p_mat' => '1027')); //Obtengo la tabla de previas $tabla = $crawler->filter('table table tbody'); //PREVIAS DE CURSO $previas_curso = array(); $tabla->filter('tr')->each(function ($node, $index) { global $client; if ($index == 0) { } else { //Obtengo los cursos hasta que aparezca la palabra examen en la 1era columna $tipo = $node->filter('td')->eq(0)->text(); if ($tipo == ' Curso ' or strlen($tipo) == 4) {
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info("Welcome to OBIKAS COurse List Crawler\n"); $time1 = time(); $courses = array(); $obikas_data = array(); $client = new Client(); $obikas = "http://registration.boun.edu.tr"; $crawler = $client->request('GET', $obikas . '/schedule.htm'); $tmp = $crawler->filter('option')->each(function ($node) { return $node->extract(array('value'))[0]; }); $this->info("OBIKAS Semester List:"); foreach ($tmp as $key => $value) { echo $key . " => " . $value . "\n"; } do { $selected_semester = $this->ask('Please enter the semester number: '); if ($selected_semester != 0 && empty($selected_semester) || !isset($tmp[$selected_semester])) { $this->info("Wrong semester number. "); } } while ($selected_semester != 0 && empty($selected_semester) || !isset($tmp[$selected_semester])); //dd(($tmp)); $form = $crawler->selectButton('Go')->form(); $form['semester'] = $tmp[$selected_semester]; echo "\nGetting department list..."; $crawler = $client->submit($form); echo "DONE\n"; $tmp = $crawler->filter('td > a')->each(function ($node) { return $node->extract(array('href'))[0]; }); echo "\nGetting course list"; foreach ($tmp as $value) { echo "."; $crawler2 = $client->request('GET', $obikas . $value); $tmp = $crawler2->filter('body > font > table > tr')->each(function ($node) { $tmp2 = $node->filter('td')->each(function ($node2) { return $node2->text(); }); return $tmp2; }); $column_names = $tmp[2]; //$obikas_data[$tmp[0][1]][$tmp[1][1]]; foreach (array_slice($tmp, 3) as $value2) { $tmp_array = null; foreach ($value2 as $key => $cell) { if ($column_names[$key] == "Code.Sec") { $tmp_array['code'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Name") { $tmp_array['name'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Instr.") { $tmp_array['instructor'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Cr.") { $tmp_array['credits'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Ects") { $tmp_array['credits'] .= '/' . trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Days") { $tmp_array['days'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Hours") { $tmp_array['hours'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Rooms") { $tmp_array['rooms'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } } $courses[] = $tmp_array; } } $data = null; $tmp_psorlab = null; $tmp_course = null; foreach ($courses as $course) { if ($course['name'] == 'LAB' || $course['name'] == 'P.S.') { $tmp_psorlab[] = $course; } else { if (count($tmp_psorlab) > 0) { $i = 1; foreach ($tmp_psorlab as $psorlab) { $psorlab['code'] = $tmp_course['code'] . ' ' . $psorlab['name'] . ' ' . $i++; $psorlab['credits'] = ''; $psorlab['name'] = $tmp_course['name']; $data[] = $psorlab; } $tmp_psorlab = null; } $data[] = $course; $tmp_course = $course; } } $this->info("\n\nGetting course list is DONE."); file_put_contents(public_path() . '/courses.json', json_encode($data)); $this->info("Course list saved to " . public_path() . '/courses.json'); $this->info("\nTotal Course Count: " . count($courses) . ", Execution Time: " . round((time() - $time1) / 60, 2) . " minutes."); }
/** * Post a comment to drupal.org. * * @param int $issue_id * The drupal.org node ID to post the comment to. * @param string $comment * Text for the comment field. * @param string $patch * Optional, file name to attach as patch. */ function post_comment($issue_id, $comment, $patch = NULL) { global $debug; if ($debug) { print $comment; return; } static $client; if (!$client) { // Perform a user login. global $drupal_user, $drupal_password; $client = new Client(); $crawler = $client->request('GET', 'https://drupal.org/user'); $form = $crawler->selectButton('Log in')->form(); // $user and $password must be set in user_password.php. $crawler = $client->submit($form, array('name' => $drupal_user, 'pass' => $drupal_password)); $login_errors = $crawler->filter('.messages-error'); if ($login_errors->count() > 0) { logger("Login to drupal.org failed."); exit; } } $issue_page = $client->request('GET', "https://www.drupal.org/node/{$issue_id}"); $comment_form = $issue_page->selectButton('Save')->form(); $form_values['nodechanges_comment[comment_body][und][0][value]'] = $comment; // We need to HTML entity decode the issue summary here, otherwise we // would post back a double-encoded version, which would result in issue // summary changes that we don't want to touch. $form_values['body[und][0][value]'] = html_entity_decode($comment_form->get('body[und][0][value]')->getValue(), ENT_QUOTES, 'UTF-8'); if ($patch) { // There can be uploaded files already, so we need to iterate to the most // recent file number. $file_nr = 0; while (!isset($comment_form["files[field_issue_files_und_{$file_nr}]"])) { $file_nr++; } $comment_form["files[field_issue_files_und_{$file_nr}]"]->upload($patch); $status = $comment_form['field_issue_status[und]']->getValue(); // Set the issue to "needs review" if it is not alreay "needs review" or RTBC. if ($status != 8 && $status != 14) { $comment_form['field_issue_status[und]']->setValue(8); } } $client->submit($comment_form, $form_values); }
<?php use Goutte\Client; $client = new Client(); $crawler = $client->request('GET', 'https://www.flysaa.com/za/en/searchpnr.secured?loc=za&lan=en'); $form = $crawler->selectButton('LOGIN')->form(); $form['pnrCode'] = 'ZYF002'; $form['surName'] = 'Moolman'; $form['windowResLogin'] = ''; $form['abmjasa'] = 'SEARCH'; $crawler = $client->submit($form); if (strpos($crawler->text(), 'Your reservation number could not be found') !== false) { echo 'Ticket could not be verified'; } else { echo 'Ticket Verified'; }
<?php require_once 'goutte.phar'; use Goutte\Client; $client = new Client(); // Pagina de previas $crawler = $client->request('GET', 'http://www1.bedelias.edu.uy/ingenieria/actas_exam.sel_per_car'); //Obtengo la tabla de previas $tabla = $crawler->filter('table table'); $valores_periodos = array(); $periodos = $tabla->filter("select[name='p_permes'] option")->each(function ($node, $index) { global $valores_periodos; array_push($valores_periodos, $node->text()); }); var_dump($valores_periodos); // Obtengo el boton del formulario $form = $crawler->selectButton('Aceptar')->form(); $crawler = $client->submit($form, array('p_permes' => $valores_periodos[2], "p_curri" => "C", "p_carrcic" => "7200")); echo $crawler->html();
/** * @Route("/hsm/v1/api/hotels/search", name="hotels") * @Method({"GET"}) * * @param Request $request * * @return JsonResponse */ public function getHotelsAction(Request $request) { // Prepare data from request for form submission $origin = $request->query->get('departingAirportCode'); $destination = $request->query->get('airportCode'); $startDate = \DateTime::createFromFormat('Y-m-d', $request->query->get('travelStartDate')); $startDate = $startDate->format('n/j/Y'); $endDate = \DateTime::createFromFormat('Y-m-d', $request->query->get('travelEndDate')); $endDate = $endDate->format('n/j/Y'); $rooms = $request->query->get('rooms'); $adults = (int) $request->query->get('adults'); $children = (int) $request->query->get('children'); $flightPrice = (int) $request->query->get('flightPrice'); $formParams = array('ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$origin' => $origin, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$destination' => $destination, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$departure' => $startDate, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$return' => $endDate, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$passengers$numrooms' => 1, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$passengers$pr$ctl00$pi$adults' => $adults, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$passengers$pr$ctl00$pi$children' => $children, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$hotelcheckin' => $startDate, 'ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$hotelcheckout' => $endDate); if ($children > 0) { $i = 1; while ($i <= $children) { $formParams['ctl00$ctl01$ContentPlaceHolder$ContentPlaceHolder$SearchComponents$scc$rt$passengers$pr$ctl00$pi$cr$ctl0' . $i . '$ChildAgeInput'] = rand(1, 14); // hardcode children age since it is not receive from "Priceline" call $i++; } } // Access and submit form $client = new Client(); $crawler = $client->request('GET', 'http://package.barcelo.com/Search/Default.aspx'); $form = $crawler->selectButton('Search')->form(); $client->submit($form, $formParams); // Select flight before accessing hotels page, so that it reflects correct price $flightDepartCrawler = $client->request('GET', 'http://package.barcelo.com/Availability/Default.aspx?itin=1&cmpt=A&leg=1'); $itemIds = $flightDepartCrawler->filter('.airContainer2')->each(function (Crawler $node, $i) use($flightPrice) { $price = $node->filter('.airPrice2')->text(); $price = (int) str_replace(array('$', ','), '', $price); if ($price === $flightPrice) { $value = $node->filter('#Button3')->getNode(0)->getAttribute('onclick'); $expl = explode(',', $value); $itemId = preg_replace('/\'/', '', $expl[1]); return $itemId; } return null; }); foreach ($itemIds as $itemId) { if (!is_null($itemId)) { $jsonItem = new \stdClass(); $jsonItem->itinerary = 1; $jsonItem->itemId = $itemId; $jsonItem->legNumber = 1; $jsonItem->availabilityFlow = 'StandardToModalFlow'; $json = '{"itinerary":1,"itemId":"' . $itemId . '","legNumber":1,"availabilityFlow":"StandardToModalFlow"}'; $client->request('POST', 'http://package.barcelo.com/availability/AvailabilityAddItem.asmx/AddAirItem', array(), array(), array('HTTP_CONTENT_TYPE' => 'application/json'), $json); break; } } $crawler = $client->request('GET', 'http://package.barcelo.com/Availability/Default.aspx?itin=1&cmpt=H'); // Select elements from crawler $nameList = $crawler->filter('.hotelTitleZone2')->extract(array('_text')); $priceList = $crawler->filter('.componentPriceHotel2')->extract(array('_text')); $locationList = $crawler->filter('.hotelLocationZone')->extract(array('_text')); $landmarkList = $crawler->filter('.hotelLandmark')->extract(array('_text')); $imageFilterList = $crawler->filter('.imgPosition'); $imageList = array(); foreach ($imageFilterList as $element) { $imageList[] = $element->getAttribute('src'); } unset($imageFilterList); $response = array(); $i = 0; while ($i < count($nameList)) { $hotel = new \stdClass(); $hotel->id = hash('md5', time() . rand()); $hotel->url = null; $hotel->name = trim(preg_replace('/\\s\\s+/', '', $nameList[$i])); $hotel->address = ''; // sa completam cu adresa corecta dupa ce incarcam harta sau sa punem locationList? $hotel->addressComponents = array(); $hotel->phone = null; $hotel->latitude = ''; $hotel->longitude = ''; $hotel->mapurl = ''; $hotel->imageUrl = $imageList[$i]; $hotel->distanceFromAirport = $this->extractDistance($landmarkList[$i]); $hotel->description = null; $hotel->score = ''; $hotel->location = $this->extractLocation($locationList[$i]); $hotel->rooms = array(); $hotel->dining = null; $hotel->accommodations = null; $hotel->amenities = null; $hotel->featured = null; $hotel->slideshowimages = null; // extract room information $val = $crawler->filter('#_f' . $i)->filter('input[name="hotelComponentBtn"]')->getNode(0)->getAttribute('onclick'); preg_match_all('/\\?(.*?)\'/', $val, $out); $partUrl = '?' . trim($out[1][0]); $roomInfoCrawler = $client->request('GET', 'http://package.barcelo.com/Availability/RatesForHotel.aspx' . $partUrl); $roomTypeNameList = $roomInfoCrawler->filter('.roomTypeName2')->extract('_text'); $roomPriceList = $roomInfoCrawler->filter('.roomSelect')->extract('_text'); $j = 0; while ($j < count($roomTypeNameList)) { $room = new \stdClass(); $room->name = trim(preg_replace('/\\s\\s+/', '', $roomTypeNameList[$j])); $room->roomRecId = hash('md5', time() . rand()); $room->description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec neque felis, vestibulum eu viverra eget, maximus quis lacus. Vestibulum euismod in erat id consequat.'; $room->image = ''; $room->numQualified = null; $room->availCodeID = 1; $guestCount = new \stdClass(); $guestCount->nights = array(); $totalPrice = $this->extractTotalPrice($roomPriceList[$j]); $guestCount->regularPrice = $totalPrice; $guestCount->totalPrice = $totalPrice; $guestCount->taxes = 0; $guestCount->numGuests = $adults + $children; $room->guestCount = $guestCount; $hotel->rooms[] = $room; $j++; } $response[] = $hotel; $i++; } return new JsonResponse($response); }
/** * Performs the user login on drupal.org. * * @return \Goutte\Client * The client holding the authenticated session. */ private function login() { $client = new Client(); $crawler = $client->request('GET', 'https://www.drupal.org/user'); $form = $crawler->selectButton('Log in')->form(); $crawler = $client->submit($form, ['name' => $this->user, 'pass' => $this->password]); // @todo this does not work for 2 factor authentication accounts. $login_errors = $crawler->filter('.messages-error'); if ($login_errors->count() > 0) { throw new Exception('Login on drupal.org failed for user ' . $this->user); } return $client; }
session_start(); /* * greatrevenueproperty@gmail.com * GR1qaz2wsx */ set_time_limit(0); header('Content-Type: text/html; charset=utf-8'); include 'vendor/autoload.php'; use Goutte\Client; $client = new Client(); $a = array(); $crawler = $client->request('GET', 'http://crm.bkkcitismart.com/'); $form = $crawler->selectButton('')->form(); //$crawler = $client->submit($form, array('data[User][user_name]' => "akekarirk_h", 'data[User][password]' => "waiwaiwai01")); $crawler = $client->submit($form, array('data[User][user_name]' => $_GET['username'], 'data[User][password]' => $_GET['password'])); $crawler = $client->request('GET', "http://crm.bkkcitismart.com/Auth"); $crawler = $client->request('GET', 'http://crm.bkkcitismart.com/Properties'); $crawler = $client->request('GET', 'http://crm.bkkcitismart.com/properties/index/page:' . $_GET['page']); $regexBookMark = '/(\'\\/bookmark_group\\/bookmarkgrp_popup\\/runningnumber:)\\w+(\\/prop_id:)\\d+(\\/user_id:)\\d+\'/'; $regexEdit = '/(\'\\/properties\\/edit\\/prop_id:)\\d+(\\/ref_no:)\\w+\'/'; $regexView = '/(\'\\/properties\\/propertyviewProject\\/prop_id:)\\d+\'/'; $dirFile = "edit"; if ($_GET["download_type"] == "edit") { $regex = $regexEdit; $dirFile = "edit"; } else { if ($_GET["download_type"] == "view") { $regex = $regexView; $dirFile = "view"; }
/** * get moneyforward csv data * * @author egmc */ require __DIR__ . "/vendor/autoload.php"; use Goutte\Client; $login_url = 'https://moneyforward.com/users/sign_in'; $csv_url = 'https://moneyforward.com/cf/csv'; if ($argc < 3) { die("usage: php {$argv['0']} your_id your_password (optional)date[yyyy-mm]" . PHP_EOL); } $login_id = $argv[1]; $password = $argv[2]; $datetime = new DateTime(); if (isset($argv[3])) { $datetime = new DateTime($argv[3]); } $params = ['from' => $datetime->format('Y/m') . "/01", 'month' => $datetime->format('m'), 'year' => $datetime->format('Y')]; $client = new Client(); $crawler = $client->request('GET', $login_url); $form = $crawler->selectButton('commit')->form(); $crawler = $client->submit($form, ['user[email]' => $login_id, 'user[password]' => $password]); $query = http_build_query($params); $client->followRedirects(false); $client->request('GET', "{$csv_url}?{$query}"); if ($client->getResponse()->getStatus() == "200") { echo $client->getResponse()->getContent(); } else { die("failed to get csv data" . PHP_EOL); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //dd(count(null)); $time1 = time(); $courses = array(); $obikas_data = array(); $client = new Client(); $obikas = "http://registration.boun.edu.tr"; $crawler = $client->request('GET', $obikas . '/schedule.htm'); $tmp = $crawler->filter('option')->each(function ($node) { return $node->extract(array('value'))[0]; }); foreach ($tmp as $value) { $obikas_data[$value] = null; } //dd(key($obikas_data)); $form = $crawler->selectButton('Go')->form(); $form['semester'] = key($obikas_data); $crawler = $client->submit($form); $tmp = $crawler->filter('td > a')->each(function ($node) { return $node->extract(array('href'))[0]; }); foreach ($tmp as $value) { $crawler2 = $client->request('GET', $obikas . $value); $tmp = $crawler2->filter('body > font > table > tr')->each(function ($node) { $tmp2 = $node->filter('td')->each(function ($node2) { return $node2->text(); }); return $tmp2; }); $column_names = $tmp[2]; //$obikas_data[$tmp[0][1]][$tmp[1][1]]; foreach (array_slice($tmp, 3) as $value2) { $tmp_array = null; foreach ($value2 as $key => $cell) { //$obikas_data[$tmp[0][1]][$tmp[1][1]][$value[0]][$column_names[$key]] = trim(trim($cell), chr(0xC2).chr(0xA0)); //$tmp_array[$column_names[$key]] = trim(trim($cell), chr(0xC2).chr(0xA0)); if ($column_names[$key] == "Code.Sec") { $tmp_array['code'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Name") { $tmp_array['name'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Instr.") { $tmp_array['instructor'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Cr.") { $tmp_array['credits'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Ects") { $tmp_array['credits'] .= '/' . trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Days") { $tmp_array['days'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Hours") { $tmp_array['hours'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } if ($column_names[$key] == "Rooms") { $tmp_array['rooms'] = trim(trim($cell), chr(0xc2) . chr(0xa0)); } } $courses[] = $tmp_array; /*if ($tmp_array['name'] == 'LAB' || $tmp_array['name'] == 'P.S.') { //$tmp_array['code'] = end($courses)['code'] . ' ' . $tmp_array['name']; $tmp_array['code'] = $tmp_array['code'] . ' ' . $tmp_array['name']; $tmp_array['credits'] = ''; $tmp_array['name'] = end($courses)['name']; $tmp_psorlab[] = $tmp_array; }else{ if(count($tmp_psorlab)>0){ foreach ($tmp_psorlab as $psorlab) { $courses[] = $psorlab; } $tmp_psorlab = array(); }else{ $courses[] = $tmp_array; } }*/ /*if($tmp_array['name'] == 'LAB' || $tmp_array['name'] == 'P.S.'){ $tmp_psorlab[] = $tmp_array; }else{ $tmp_end = end($courses); if(count($tmp_psorlab) == 1){ $tmp_psorlab[0]['code'] = $tmp_end['code'].' '.$tmp_psorlab[0]['name']; $tmp_psorlab[0]['credits'] = ''; $tmp_psorlab[0]['name'] = $tmp_end['name']; $courses[] = $tmp_psorlab[0]; }elseif(count($tmp_psorlab) > 1){ $i = 1; foreach ($tmp_psorlab as $psorlab) { $psorlab['code'] = $tmp_end['code'].' '.$psorlab['name'].' '.$i++; $psorlab['credits'] = ''; $psorlab['name'] = $tmp_end['name']; $courses[] = $psorlab; } }else(count($tmp_psorlab) == 0){ $courses[] = $tmp_array; } $tmp_psorlab = null; }*/ //$obikas_data[$tmp[0][1]][$tmp[1][1]][$value[0]] = $tmp_array; } } $data = null; $tmp_psorlab = null; $tmp_course = null; foreach ($courses as $course) { if ($course['name'] == 'LAB' || $course['name'] == 'P.S.') { $tmp_psorlab[] = $course; } else { if (count($tmp_psorlab) > 0) { $i = 1; foreach ($tmp_psorlab as $psorlab) { $psorlab['code'] = $tmp_course['code'] . ' ' . $psorlab['name'] . ' ' . $i++; $psorlab['credits'] = ''; $psorlab['name'] = $tmp_course['name']; $data[] = $psorlab; } $tmp_psorlab = null; } $data[] = $course; $tmp_course = $course; } } file_put_contents(public_path() . '/courses.json', json_encode($data)); echo (time() - $time1) / 60 . ' dakika sürdü. Toplam kayıt sayısı: ' . count($courses); //$crawler = $crawler->filter('body > table > tbody > tr > td'); //dd($crawler->text()); }
/** * Validates an Safair ticket via web scraper * * @param array $ticketDetails * @return Boolean */ protected function verifySafair($ticketDetails) { $client = new Client(); //Do not verify SSL for this host as we get SSL errors... $guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false))); $client->setClient($guzzleClient); $crawler = $client->request('GET', 'https://www.flysafair.co.za/manage/Manage-booking'); $form = $crawler->selectButton('Retrieve booking')->form(); $form['PNR'] = $ticketDetails['ticketref']; $form['lastName'] = Auth::user()->lastname; $crawler = $client->submit($form); if (!strpos($crawler->text(), "\n Your booking could not be found. Please check the spelling and try again.\n ")) { return false; } else { return true; } }
/** * Execute the console command. * * @return mixed */ public function handle() { $client = new Client(); $crawler = $client->request('GET', 'http://rustorka.com/forum/tracker.php?f[]=-1'); $form = $crawler->filter(".borderless.bCenter input")->selectButton('Вход')->form(); $crawler = $client->submit($form, array('login_username' => env('RUSTORKA_LOGIN'), 'login_password' => env('RUSTORKA_PASSWORD'))); $this->processPage($crawler); $links = []; $links = $crawler->filter("div.bottom_info a")->each(function (Crawler $node) use($links) { $links = $node->link(); return $links; }); if ($links) { foreach ($links as $key => $link) { if ($key > 0) { $crawler = $client->click($link); $this->processPage($crawler); } } } }