国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

? ??? ?? PHP ???? Selenium? ???? ??? ????? ? ??? ??? ????

Selenium? ???? ??? ????? ? ??? ??? ????

Jul 25, 2016 am 08:46 AM

傳統(tǒng)的 cURL 無(wú)法執(zhí)行頁(yè)面中的瀏覽器腳本,并且在抓取一些對(duì)爬蟲有限制的網(wǎng)頁(yè)時(shí),往往要設(shè)定詳細(xì)的 http header 來(lái)突破限制,編寫起來(lái)較為復(fù)雜。

Selenium簡(jiǎn)介:

Selenium 是一個(gè)用于Web應(yīng)用程序測(cè)試的工具(用處也不僅僅是測(cè)試)。
Selenium 直接使用瀏覽器運(yùn)行,像真正的用戶在操作。支持較多的瀏覽器。

組件

Selenium IDE:Firefox插件,有錄制腳本的功能。支持自動(dòng)錄制動(dòng)作和自動(dòng)生成其他語(yǔ)言的自動(dòng)化腳本。

Selenium Remote Control (RC) :支持多種平臺(tái)(Windows,Linux)和多瀏覽器(IE,F(xiàn)irefox,Opera,Safari,Chrome),可以用多種語(yǔ)言(Java,Ruby,Python,Perl,PHP,C#)編寫用例。

Selenium Grid :允許Selenium-RC 針對(duì)規(guī)模龐大的測(cè)試案例集或者需要在不同環(huán)境中運(yùn)行的測(cè)試案例集進(jìn)行擴(kuò)展。


實(shí)例:驅(qū)動(dòng) chrome 模擬登入淘寶,獲取頁(yè)面信息

1.前往項(xiàng)目主頁(yè):SeleniumHQ 下載

Selenium Server (formerly the Selenium RC Server)

Third Party Browser Drivers NOT DEVELOPED by seleniumhq

(選擇chrome的driver)

Third Party Language Bindings NOT DEVELOPED by seleniumhq

(選擇PHP by Adam Goucher (SeHQ recommended php client))

2.打開(kāi) selenium

  1. java -jar path_to_selenium.jar
  2. [-timeout 0]
  3. [-Dwebdriver.server.session.timeout=0]
  4. -Dwebdriver.chrome.driver="path_to_chrome_driver"
  5. -browser [-timeout=0] [-browserTimeout=0]
  6. browserName=chrome,[timeout=0]
復(fù)制代碼

如需長(zhǎng)時(shí)間運(yùn)行請(qǐng)酌情設(shè)置各 '[ ]' 中的超時(shí)時(shí)間

3.php代碼

  1. function waitForAjax() {
  2. global $session;
  3. do {
  4. sleep(1);
  5. } while($session->execute(array('script' => "return (document.readyState != 'complete')", 'args' => array())));
  6. } //該函數(shù)會(huì)把腳本掛起直到等待到Ajax結(jié)束
  7. require_once "webdriver/PHPWebDriver/__init__.php";
  8. // 引入 selenium 的PHP封裝函數(shù)庫(kù)
  9. // 下載地址:https://github.com/Element-34/php-webdriver
  10. // 文檔中有各種操作瀏覽器方法,如獲取所有cookie等
  11. $wd_host = 'http://127.0.0.1:4444/wd/hub';
  12. $web_driver = new PHPWebDriver_WebDriver($wd_host);
  13. $session = $web_driver->session('chrome');
  14. //設(shè)置超時(shí)時(shí)間
  15. $session->implicitlyWait(5);
  16. $session->setScriptTimeout(5);
  17. $session->setPageLoadTimeout(15);
  18. //打開(kāi)連接
  19. $session->open('http://login.m.taobao.com/login.htm?tpl_redirect_url=http://m.taobao.com');
  20. //輸入驗(yàn)證碼用,如果需要的話
  21. sleep(5);
  22. //請(qǐng)?jiān)O(shè)置好帳號(hào)密碼
  23. $session->element('css selector', 'input[name=TPL_username]')->value(array('value' => str_split('your_username')));
  24. $session->element('css selector', 'input[name=TPL_password]')->value(array('value' => str_split('your_password')));
  25. //模擬點(diǎn)擊登入按鈕
  26. $elements = $session->element('css selector', '.c-btn-oran-big')->click();
  27. //打開(kāi) m.taobao.com,此時(shí)已獲取到cookie
  28. $session->open('http://m.taobao.com/');
  29. //等待ajax加載完畢
  30. waitForAjax();
  31. $elements = $session->element('css selector', 'body')->text();
  32. //獲得了登入后ajax執(zhí)行完畢時(shí)的頁(yè)面內(nèi)容
  33. ?>
復(fù)制代碼

之后便可以按需對(duì) $session 實(shí)例進(jìn)行 element 方法的各種操作。

支持以下方式進(jìn)行選擇元素

id xpath link text partial link text name tag name class name css selector
PS:各種庫(kù)對(duì)Ajax情況的檢測(cè)方法

jQuery: "jQuery.active"

Prototype: "Ajax.activeRequestCount"

Dojo: "dojo.io.XMLHTTPTransport.inFlight.length"

???, ???


? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
PHP ?? ??? ??????? PHP ?? ??? ??????? Jul 17, 2025 am 04:16 AM

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP?? ?? ???? ???? ???? ??? ?????? PHP?? ?? ???? ???? ???? ??? ?????? Jul 08, 2025 am 02:37 AM

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP?? ?? ?? PHP?? ?? ?? Jul 18, 2025 am 04:57 AM

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP?? ???? ??? ?????? PHP?? ???? ??? ?????? Jul 11, 2025 am 03:12 AM

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

PHP ?? ?? ? PHP ?? ?? ? Jul 18, 2025 am 04:51 AM

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

?? PHP : ??? ??? ?? PHP : ??? ??? Jul 18, 2025 am 04:54 AM

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

PHP?? ??? ? ???? ??? ????? ?? PHP?? ??? ? ???? ??? ????? ?? Jul 12, 2025 am 03:15 AM

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.

?? PHP ?? ??? ?? PHP ?? ??? Jul 18, 2025 am 04:52 AM

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2

See all articles