5

我正在尝试通过 selenium 将 VPN 连接作为 chrome 扩展与 Hola 进行交互。它被读入并且浏览器使用 chrome 扩展名呈现,但是我想向 netflix 发出获取请求并存储所有 IP。如何发出获取请求并使用 Hola 更改列表中每个国家/地区的 IP?

谢谢。

from browsermobproxy import Server
import os, pdb
from selenium import webdriver


def bootServer():
    server = Server("/Users/Desktop/browsermob-proxy-2.1.2/bin/browsermob-proxy")
    server.start()
    proxy = server.create_proxy()
    return proxy, server


def bootDriver(proxy):
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_extension('/Users/Desktop/extension.crx')
    chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
    driver = webdriver.Chrome(chrome_options = chrome_options, executable_path = os.getcwd() + "/chromedriver")
    return driver 

def getCountryCodes():
    data = []
    with open("countryCodes.txt") as f:
        content = f.readlines()
        for cc in content:
            data.append(cc.strip())
    return data 

def main():
    proxy, server = bootServer()
    proxy.new_har("netflix")
    driver = bootDriver(proxy)
    countryCodes = getCountryCodes()
    for cc in countryCodes:
        pdb.set_trace()
        driver.get("https://www.netflix.com/watch/80028554?trackId=14170082&tctx=0%2C0%2C8c294fdd-6462-4eae-abd7-6d519143971e-2851377")
        proxy.new_page("netflix")

    ips = [dat['serverIPAddress'] for dat in proxy.har['log']['entries']]
    pdb.set_trace()
    server.stop()
    driver.quit()

main()
4

0 回答 0