Skip to content

Commit 4369e7b

Browse files
committed
Update examples
1 parent 3220918 commit 4369e7b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

examples/cdp_mode/raw_proxy.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from seleniumbase import decorators
2+
from seleniumbase import sb_cdp
3+
4+
# Change this to "ip:port" or "user:pass@ip:port"
5+
proxy = None
6+
7+
8+
@decorators.print_runtime("CDP Proxy Example")
9+
def main():
10+
url = "https://api.ipify.org/"
11+
sb = sb_cdp.Chrome(url, lang="en", pls="none", proxy=proxy)
12+
ip_address = sb.get_text("body")
13+
if "ERR" in ip_address:
14+
raise Exception("Failed to determine IP Address!")
15+
print("\n\nMy IP Address = %s\n" % ip_address)
16+
sb.open("https://ipinfo.io/%s" % ip_address)
17+
sb.sleep(2)
18+
sb.wait_for_text(ip_address, "h1", timeout=20)
19+
sb.find_element('[href="/signup"]')
20+
sb.wait_for_text("Hosted domains", timeout=20)
21+
sb.highlight("h1")
22+
pop_up = '[role="dialog"] span.cursor-pointer'
23+
sb.click_if_visible(pop_up)
24+
sb.highlight("#block-summary")
25+
sb.click_if_visible(pop_up)
26+
sb.highlight("#block-geolocation")
27+
sb.click_if_visible(pop_up)
28+
sb.sleep(2)
29+
print("Displaying Host Info:")
30+
text = sb.get_text("#block-summary").split("Hosted domains")[0]
31+
rows = text.split("\n")
32+
data = []
33+
for row in rows:
34+
if row.strip() != "":
35+
data.append(row.strip())
36+
print("\n".join(data).replace('\n"', ' "'))
37+
print("\nDisplaying GeoLocation Info:")
38+
text = sb.get_text("#block-geolocation")
39+
text = text.split("IP Geolocation data")[0]
40+
rows = text.split("\n")
41+
data = []
42+
for row in rows:
43+
if row.strip() != "":
44+
data.append(row.strip())
45+
print("\n".join(data).replace('\n"', ' "'))
46+
sb.sleep(3)
47+
48+
49+
if __name__ == "__main__":
50+
main()

examples/proxy_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ def test_proxy(self):
1515
self.get_new_driver(page_load_strategy="none")
1616
self.open("https://api.ipify.org/")
1717
ip_address = self.get_text("body")
18+
if "ERR" in ip_address:
19+
raise Exception("Failed to determine IP Address!")
1820
print("\n\nMy IP Address = %s\n" % ip_address)
1921
self.open("https://ipinfo.io/%s" % ip_address)
2022
self.sleep(2)
2123
self.wait_for_text(ip_address, "h1", timeout=20)
2224
self.wait_for_element_present('[href="/signup"]')
2325
self.wait_for_text("Hosted domains", timeout=20)
2426
self.highlight("h1")
27+
pop_up = '[role="dialog"] span.cursor-pointer'
28+
self.click_if_visible(pop_up)
2529
self.highlight("#block-summary")
30+
self.click_if_visible(pop_up)
2631
self.highlight("#block-geolocation")
32+
self.click_if_visible(pop_up)
2733
self.sleep(2)
28-
self.click_if_visible("span.ipinfo-modal__close")
2934
print("Displaying Host Info:")
3035
text = self.get_text("#block-summary").split("Hosted domains")[0]
3136
rows = text.split("\n")

0 commit comments

Comments
 (0)