Selenium +浏览器Mob代理+ Chrome扩展(Hola)

时间:2016-08-23 04:20:23

标签: python google-chrome selenium selenium-webdriver browsermob-proxy

我正在尝试通过硒与Hola将VPN连接作为铬扩展进行交互。它被读入并且浏览器使用chrome扩展进行渲染,但是我想向netflix发出get请求并存储所有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()

0 个答案:

没有答案