Home  >  Article  >  Backend Development  >  PHP controls browser actions

PHP controls browser actions

PHPz
PHPzOriginal
2017-04-04 16:08:082958browse

System environment:

  • Mac

Principle:

  • 1: Use phpLanguage writing control script

  • 2: The script communicates with the chrome driver (chromedriver) program

  • 3: chromedriver controls chrome execution operations

Process: php script => chromedriver => chrome

Software needed

##Operation Demo

  • 1:

    Installationphp-webdriver Create a demo directory and execute
    composer require<a href="http://www.php.cn/wiki/136.html" target="_blank"> facebook/webdriver</a>

  • 2: Download chromedriver, double-click to run

  • 3: In the demo directory, create the demo.php file

<?php
// An example of using php-webdriver.
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once(&#39;vendor/autoload.php&#39;);

//chromedriver默认端口
$host = &#39;http://localhost:9515&#39;;

$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome(), 50000);
$driver->get('http://www.baidu.com');

$cookies = $driver->manage()->getCookies();
print_r($cookies);


echo "The title is '" . $driver->getTitle() . "'\n";
echo "The current URI is '" . $driver->getCurrentURL() . "'\n";

//关闭浏览器
$driver->quit();
  • 4: Run demo.php


    php demo.php

The above is the detailed content of PHP controls browser actions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn