참고 :이 프로젝트는 Selenium 구문에서 멀어지고 있습니다.
선적 서류 비치
CDP-Patches (Headfull 만 해당) 가이 문제를 해결해야합니다
(어느 때에 그것을 통합 할 것입니다)
Discord 에서 무인 커뮤니티에 합류하십시오. :)
또한 최신 구현은 Dev-Branch를 참조하십시오.
pip uninstall -y selenium-driverless
pip install https://github.com/kaliiiiiiiiii/Selenium-Driverless/archive/refs/heads/dev.zip이 프로젝트는 현재 후원되지 않습니다.
pip install selenium-driverless from selenium_driverless import webdriver
from selenium_driverless . types . by import By
import asyncio
async def main ():
options = webdriver . ChromeOptions ()
async with webdriver . Chrome ( options = options ) as driver :
await driver . get ( 'http://nowsecure.nl#relax' , wait_load = True )
await driver . sleep ( 0.5 )
await driver . wait_for_cdp ( "Page.domContentEventFired" , timeout = 15 )
# wait 10s for elem to exist
elem = await driver . find_element ( By . XPATH , '/html/body/div[2]/div/main/p[2]/a' , timeout = 10 )
await elem . click ( move_to = True )
alert = await driver . switch_to . alert
print ( alert . text )
await alert . accept ()
print ( await driver . title )
asyncio . run ( main ())비동기, 버그는 기대할 수 있습니다
from selenium_driverless . sync import webdriver
options = webdriver . ChromeOptions ()
with webdriver . Chrome ( options = options ) as driver :
driver . get ( 'http://nowsecure.nl#relax' )
driver . sleep ( 0.5 )
driver . wait_for_cdp ( "Page.domContentEventFired" , timeout = 15 )
title = driver . title
url = driver . current_url
source = driver . page_source
print ( title ) from selenium_driverless import webdriver
options = webdriver . ChromeOptions ()
options . debugger_address = "127.0.0.1:2005"
# specify if you don't want to run remote
# options.add_argument("--remote-debugging-port=2005")
async with webdriver . Chrome ( options = options ) as driver :
await driver . get ( 'http://nowsecure.nl#relax' , wait_load = True )참고 : Asyncio는 권장되며 스레딩은 독립적 인 WebDriver.Chrome 인스턴스에서만 작동합니다.
from selenium_driverless . sync import webdriver
from selenium_driverless . utils . utils import read
from selenium_driverless import webdriver
import asyncio
async def target_1_handler ( target ):
await target . get ( 'https://abrahamjuliot.github.io/creepjs/' )
print ( await target . title )
async def target_2_handler ( target ):
await target . get ( "about:blank" )
await target . execute_script ( await script = read ( "/files/js/show_mousemove.js" ))
await target . pointer . move_to ( 500 , 500 , total_time = 2 )
async def main ():
options = webdriver . ChromeOptions ()
async with webdriver . Chrome ( options = options ) as driver :
target_1 = await driver . current_target
target_2 = await driver . new_window ( "tab" , activate = False )
await asyncio . gather (
target_1_handler ( target_1 ),
target_2_handler ( target_2 )
)
await target_1 . focus ()
input ( "press ENTER to exit" )
asyncio . run ( main ())javascript 실행하십시오 ( 고립 된 세계 에서) from selenium_driverless . sync import webdriver
from selenium_driverless import webdriver
import asyncio
async def main ():
options = webdriver . ChromeOptions ()
async with webdriver . Chrome ( options = options ) as driver :
await driver . get ( 'chrome://version' )
script = """
const proxy = new Proxy(document.documentElement, {
get(target, prop, receiver) {
if(prop === "outerHTML"){
console.log('detected access on "'+prop+'"', receiver)
return "mocked value:)"
}
else{return Reflect.get(...arguments)}
},
});
Object.defineProperty(document, "documentElement", {
value: proxy
})
"""
await driver . execute_script ( script )
src = await driver . execute_script ( "return document.documentElement.outerHTML" , unique_context = True )
mocked = await driver . execute_script ( "return document.documentElement.outerHTML" , unique_context = False )
print ( src , mocked )
asyncio . run ( main ())시각화는 @master/tests/show_mousemove.py를 참조하십시오
pointer = driver . current_pointer
move_kwargs = { "total_time" : 0.7 , "accel" : 2 , "smooth_soft" : 20 }
await pointer . move_to ( 100 , 500 )
await pointer . click ( 500 , 50 , move_kwargs = move_kwargs , move_to = True ) swtich_to.frame() 가 무인으로 더 이상 사용되지 않으면 대신 사용하십시오
iframes = await driver . find_elements ( By . TAG_NAME , "iframe" )
await asyncio . sleep ( 0.5 )
iframe_document = await iframes [ 0 ]. content_document
# iframe_document.find_elements(...) from selenium_driverless import webdriver
options = webdriver . ChromeOptions ()
# recommended usage
options . update_pref ( "download.prompt_for_download" , False )
# or
options . prefs . update ({ "download" : { "prompt_for_download" : False }})
# supported
options . add_experimental_option ( "prefs" , { "download.prompt_for_download" : False }) from selenium_driverless import webdriver
import asyncio
async def main ():
options = webdriver . ChromeOptions ()
async with webdriver . Chrome ( options = options ) as driver :
context_1 = driver . current_context
await driver . set_auth ( "username" , "password" , "localhost:5000" )
# proxy not supported on windows due to https://bugs.chromium.org/p/chromium/issues/detail?id=1310057
context_2 = await driver . new_context ( proxy_bypass_list = [ "localhost" ], proxy_server = "http://localhost:5000" )
await context_1 . current_target . get ( "https://examle.com" )
await context_2 . get ( "https://examle.com" )
input ( "press ENTER to exit:)" )
asyncio . run ( main ())다음과 같이 사용자 정의 예외 처리를 구현할 수 있습니다
import selenium_driverless
import sys
handler = ( lambda e : print ( f'Exception in event-handler: n { e . __class__ . __module__ } . { e . __class__ . __name__ } : { e } ' ,
file = sys . stderr ))
sys . modules [ "selenium_driverless" ]. EXC_HANDLER = handler
sys . modules [ "cdp_socket" ]. EXC_HANDLER = handler 버그를 찾았습니까? 자유롭게 문제를여십시오 :) 다른 질문이나 제안이 있습니까? Discord 에서 무인-커뮤니티에 가입하거나 디스크션을 열십시오
Aurin Aegerter (일명 스티브 )
이 작업은 Creative Commons Attribution-Noncommercial-Sharealike 4.0 국제 라이센스에 Section 1(k) 라이센스가 부여됩니다.
상업적 수단은 주로 상업적 이점 또는 금전적 보상을 위해 의도 된 또는 지시를받는 수단입니다.
한 달에 7'000 US-Dollar 이상의 수익을 올리는 모든 종류의 상업적 의도 또는 그에 해당하는 금전적 인 상업적 의도와의 비즈니스, 프로젝트 또는 공공 계약은이 비영리 정의의 적용을받지 않습니다.
이 프로젝트를 상업적으로 사용하려면 저자에게 문의 할 수 있습니다. 여기에는 일반적으로 현재 이익에 따라 약 5-6%의 수수료가 포함됩니다.
이 프로젝트는 교육 목적만을 위한 것입니다. 책임감있게 사용하십시오.
저자는 어떠한 보증도 제공하지 않으며 , 어떤 식 으로든 어떤 또는 어떻게 사용되는지에 대해 책임을지지 않습니다 .
영감, 코드 스 니펫 등