小编use*_*813的帖子

在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万
查看次数