|
| 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() |
0 commit comments