【问题标题】:bind traffic from selenium_webdriver(chrome) to specific network interface/tunnel将 selenium_webdriver(chrome) 的流量绑定到特定的网络接口/隧道
【发布时间】:2015-10-26 18:12:50
【问题描述】:

任务是通过特定的网络接口(在 linux 上)自动化一些浏览器活动。 因为我需要在页面上启动视频-我选择了 selenium(python) 并使用 selenium 制作了所有例程来播放视频,但应用程序通过默认界面。 问题 - 如何强制 chrome 使用例如 tun0? 注意:我看过类似的问题/答案,但由于缺乏 linux 编程经验,无法解决我的问题。如果可能,请提供分步指南,谢谢。

【问题讨论】:

  • 我发现 [solution] (daniel-lange.com/archives/…) 让网络浏览器使用特定的 IP。-BIND_ADDR=10.254.64.21 LD_PRELOAD=/usr/lib/bind.so firefox ,该命令开始新FF 的实例并且它使用特定的 net_iface 但是,我无法将其链接到 webdriver,即作为 selenium code-driver = webdriver.Chrome() 的一部分启动,它也是使用默认 net_iface 的启动 web-broser。问题 - 如何使这两个命令一起工作?

标签: python linux selenium webdriver network-interface


【解决方案1】:

为了让它在 Firefox 上工作,我跟随 https://daniel-lange.com/archives/53-Binding-applications-to-a-specific-IP.html 创建 /usr/lib/bind.so

然后我将 /usr/lib/python2.6/site-packages/selenium/webdriver/firefox/firefox_binary.py 修改为以下内容:

#self._firefox_env['LD_PRELOAD'] = self.NO_FOCUS_LIBRARY_NAME
self._firefox_env['LD_PRELOAD'] = "/usr/lib/bind.so"
self._firefox_env['BIND_ADDR'] = "198.58.118.236"

注释掉的行是原始行。

对于 Chrome,看起来你会在 service.py 中破解 self.env = env

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多