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