真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

selenium部署

  1. 安裝selenium:
    composer  require  facebook/webdriver
  2. 下載jdk(略)
  3. 下載selenium服務(wù):
    https://goo.gl/FCSwwD
  4. 運(yùn)行selenium服務(wù):
    java  -jar  selenium-server-standalone-3.14.0.jar
  5. 下載chromedriver:
    https://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip
  6. 將chromedriver放到chrome安裝目錄下:
    C:\Program Files (x86)\Google\Chrome\Application
  7. 移動(dòng)chromedriver到chrome安裝目錄:
    selenium部署
  8. 添加chrome安裝目錄下環(huán)境變量:
    selenium部署
  9. 編寫測(cè)試代碼(test.php):

    網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),成都做網(wǎng)站公司-創(chuàng)新互聯(lián)公司已向上1000+企業(yè)提供了,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷等服務(wù)!設(shè)計(jì)與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗(yàn),合理的價(jià)格為您打造企業(yè)品質(zhì)網(wǎng)站。

    get($baseUrl);
    echo consoleText($driver->getTitle()) . "\n";    //cmd.exe中文亂碼,所以需轉(zhuǎn)碼
    $topLists = $driver->findElement(WebDriverBy::className('container-top-wrapper'))->findElement(WebDriverBy::className('top-list-wrapper'))->findElements(WebDriverBy::tagName('li'));
    foreach ($topLists as $topLi) {
    $itemContent = $topLi->findElement(WebDriverBy::tagName('a'));
    echo consoleText($itemContent->getAttribute('title')) . ' : ' . consoleText($itemContent->getAttribute('href')) . "\n";
    }
    //關(guān)閉瀏覽器
    $driver->quit();
    function consoleText($text, $pageEncoding = '', $consoleEncoding = '')
    {
    // windows
    if (!$consoleEncoding) {
        if (stristr(php_uname('s'), 'win')) {
            $consoleEncoding = "GBK";
        } else {
            $consoleEncoding = 'UTF-8';
        }
    }
    return exchangeEncoding($text, $pageEncoding, $consoleEncoding);
    }
    function exchangeEncoding($text, $pageEncoding = '', $targetEncoding = 'UTF-8')
    {
    if (!$pageEncoding) {
        $pageEncoding = mb_detect_encoding($text, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
    }
    
    if ($pageEncoding != $targetEncoding) {
        return mb_convert_encoding($text,$targetEncoding,$pageEncoding);
    }
    
    return $text;
    }
    //切換至最后一個(gè)window
    function switchToEndWindow($driver)
    {
    
    $arr = $driver->getWindowHandles();
    foreach ($arr as $k => $v) {
        if ($k == (count($arr) - 1)) {
            $driver->switchTo()->window($v);
        }
    }
    }
  10. 運(yùn)行測(cè)試代碼:
    php  test.php

    selenium部署


當(dāng)前名稱:selenium部署
標(biāo)題鏈接:http://weahome.cn/article/iijsii.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部