相关疑难解决方法(0)

在Python中使用代理运行Selenium Webdriver

我试图在Python中运行Selenium Webdriver脚本来执行一些基本任务.当通过Selenium IDE界面运行时,我可以让机器人完美地运行(即:当简单地让GUI重复我的动作时).但是,当我将代码导出为Python脚本并尝试从命令行执行时,Firefox浏览器将打开但无法访问起始URL(错误将返回到命令行并且程序停止).无论我试图访问什么网站等,这都发生在我身上.

我在这里包含了一个非常基本的代码用于演示目的.我不认为我已正确包含代码的代理部分,因为返回的错误似乎是由代理生成的.

任何帮助将非常感激.

以下代码仅用于打开www.google.ie并搜索"selenium"一词.对我来说它打开一个空白的Firefox浏览器并停止.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
from selenium.webdriver.common.proxy import *

class Testrobot2(unittest.TestCase):
    def setUp(self):

        myProxy = "http://149.215.113.110:70"

        proxy = Proxy({
        'proxyType': ProxyType.MANUAL,
        'httpProxy': myProxy,
        'ftpProxy': myProxy,
        'sslProxy': myProxy,
        'noProxy':''})

        self.driver = webdriver.Firefox(proxy=proxy)
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.google.ie/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_robot2(self):
        driver = self.driver
        driver.get(self.base_url + "/#gs_rn=17&gs_ri=psy-ab&suggest=p&cp=6&gs_id=ix&xhr=t&q=selenium&es_nrs=true&pf=p&output=search&sclient=psy-ab&oq=seleni&gs_l=&pbx=1&bav=on.2,or.r_qf.&bvm=bv.47883778,d.ZGU&fp=7c0d9024de9ac6ab&biw=592&bih=665")
        driver.find_element_by_id("gbqfq").clear()
        driver.find_element_by_id("gbqfq").send_keys("selenium")

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except …
Run Code Online (Sandbox Code Playgroud)

python proxy selenium selenium-ide selenium-webdriver

59
推荐指数
9
解决办法
9万
查看次数

我如何在python webdriver中设置chrome的代理

我正在使用此代码:

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy.server.address")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
Run Code Online (Sandbox Code Playgroud)

在python webdriver中设置FF的代理.这适用于FF.如何在Chrome中设置这样的代理?我发现这个例子但不是很有帮助.当我运行脚本时没有任何反应(Chrome浏览器未启动).

python proxy google-chrome webdriver

39
推荐指数
6
解决办法
7万
查看次数

使用Python的Selenium:为firefox输入/提供http代理密码

我想使用selenium和受密码保护的代理.代理不是固定的,而是一个变量.所以这必须在代码中完成(只需在这台特定的机器上设置firefox以使用代理就不太理想了).到目前为止,我有以下代码:

fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)

fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)

driver = webdriver.Firefox(firefox_profile=fp)
driver.get("http://whatismyip.com")
Run Code Online (Sandbox Code Playgroud)

此时,弹出对话框,请求代理用户/通过.

是否有一种简单的方法:

  1. 在对话框中键入user/pass.
  2. 在较早阶段提供用户/通行证.

python firefox selenium selenium-webdriver

20
推荐指数
2
解决办法
2万
查看次数

如何使用Python + Selenium设置代理身份验证(用户和密码)

我在Python 2.7中使用Firefox WebDriver和Selenium.当我运行程序时,我的python程序启动Firefox浏览器并访问不同的网站.但是,我需要使用身份验证设置代理,这样当程序访问任何网站时,它将通过代理服务器访问.

SO上有一些类似的问题.但是,没有针对Selenium Firefox WebDriver的Python的特定解决方案.

firefox proxy-authentication python-2.7 selenium-webdriver

10
推荐指数
4
解决办法
2万
查看次数