File tree Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 4
4
with SB (uc = True , test = True , locale_code = "en" ) as sb :
5
5
url = "https://www.cloudflare.com/login"
6
6
sb .activate_cdp_mode (url )
7
- sb .sleep (2 )
7
+ sb .sleep (3 )
8
8
sb .uc_gui_handle_captcha () # PyAutoGUI press Tab and Spacebar
9
9
sb .sleep (2 )
10
10
Original file line number Diff line number Diff line change 4
4
with SB (uc = True , test = True , ad_block = True ) as sb :
5
5
url = "https://chatgpt.com/"
6
6
sb .activate_cdp_mode (url )
7
+ sb .sleep (1 )
8
+ sb .click_if_visible ('button[aria-label="Close dialog"]' )
7
9
query = "Compare Playwright to SeleniumBase in under 178 words"
8
10
sb .press_keys ("#prompt-textarea" , query )
9
11
sb .click ('button[data-testid="send-button"]' )
10
12
print ('*** Input for ChatGPT: ***\n "%s"' % query )
13
+ sb .sleep (3 )
11
14
with suppress (Exception ):
12
- # The "Send" button reappears when ChatGPT is done typing a response
13
- sb .wait_for_element ('button[data-testid="send-button"]' , timeout = 22 )
15
+ # The "Stop" button disappears when ChatGPT is done typing a response
16
+ sb .wait_for_element_not_visible (
17
+ 'button[data-testid="stop-button"]' , timeout = 20
18
+ )
14
19
chat = sb .find_element ('[data-message-author-role="assistant"] .markdown' )
15
20
soup = sb .get_beautiful_soup (chat .get_html ()).get_text ("\n " ).strip ()
16
21
print ("*** Response from ChatGPT: ***\n %s" % soup .replace ("\n :" , ":" ))
Original file line number Diff line number Diff line change @@ -65,8 +65,8 @@ async def crawl():
65
65
# Change url to something that makes ajax requests
66
66
tab = await driver .get ("https://learn.microsoft.com/en-us/" )
67
67
time .sleep (2 )
68
- for i in range (75 ):
69
- await tab .scroll_down (3 )
68
+ for i in range (20 ):
69
+ await tab .scroll_down (4 )
70
70
time .sleep (0.02 )
71
71
72
72
xhr_responses = await receiveXHR (tab , xhr_requests )
@@ -87,6 +87,5 @@ async def crawl():
87
87
88
88
if __name__ == "__main__" :
89
89
print ("<============= START: XHR Example =============>" )
90
- loop = asyncio .new_event_loop ()
91
- loop .run_until_complete (crawl ())
90
+ asyncio .run (crawl ())
92
91
print ("<============== END: XHR Example ==============>" )
Original file line number Diff line number Diff line change @@ -64,8 +64,8 @@ async def receiveXHR(page, requests):
64
64
# Change url to something that makes ajax requests
65
65
sb .cdp .open ("https://learn.microsoft.com/en-us/" )
66
66
time .sleep (2 )
67
- for i in range (15 ):
68
- sb .cdp .scroll_down (15 )
67
+ for i in range (10 ):
68
+ sb .cdp .scroll_down (8 )
69
69
70
70
loop = sb .cdp .get_event_loop ()
71
71
xhr_responses = loop .run_until_complete (receiveXHR (tab , xhr_requests ))
Original file line number Diff line number Diff line change 1
1
"""SB Manager using UC Mode for evading bot-detection."""
2
2
from seleniumbase import SB
3
3
4
- with SB (uc = True , test = True ) as sb :
4
+ with SB (uc = True , test = True , disable_csp = True ) as sb :
5
5
url = "https://steamdb.info/"
6
6
sb .uc_open_with_reconnect (url , 3 )
7
7
sb .uc_click ("a.header-login span" , 3 )
8
8
sb .uc_gui_click_captcha ()
9
- sb .assert_text ("Sign in" , "button#js-sign-in" )
9
+ sb .assert_text ("Sign in" , "button#js-sign-in" , timeout = 4 )
10
10
sb .uc_click ("button#js-sign-in" , 2 )
11
11
sb .highlight ("div.page_content form" )
12
12
sb .highlight ('button:contains("Sign in")' , scroll = False )
13
- sb .sleep (1 )
13
+ sb .set_messenger_theme (location = "top_center" )
14
+ sb .post_message ("SeleniumBase wasn't detected" , duration = 4 )
You can’t perform that action at this time.
0 commit comments