【问题标题】:Selenium: page displayed differentlySelenium:页面显示不同
【发布时间】:2014-07-30 15:35:15
【问题描述】:

我使用以下 URL 启动 firefox(不要运行它,它已被列入黑名单,我仅将其用于安全测试)。这是我使用的简单代码:

from selenium import webdriver
driver=webdriver.Firefox()
driver.get("http://addonrock.ru/Debugger.js") 

但我没有得到我想要的。我的意思是,当我通过自己在 Firefox 上键入该 URL 来运行该 URL 时,我会得到这个页面:




但是当我使用上述 URL 启动 Firefox 时,我宁愿获取此页面:



如何使用我的代码获得与图 1 相同的结果?提前感谢您的帮助。

【问题讨论】:

    标签: python firefox selenium python-3.x selenium-webdriver


    【解决方案1】:

    这是由browser.safebrowsing.malware.enabled Firefox 首选项控制的。在 Firefox 浏览器中在 about:config 中更改它会重现您所描述的行为:如果它已打开 - Firefox 会警告您有关站点 being in the malware-detected block list,如果它已关闭 - 您会看到 Firefox 根本没有加载页面。

    而且,仅供参考,这是安全首选项中的“阻止报告的攻击站点”复选框:

    通过FirefoxProfile 设置 Firefox 首选项应该会有所帮助:

    from selenium import webdriver
    
    profile = webdriver.FirefoxProfile()
    profile.set_preference('browser.safebrowsing.enabled', True)
    profile.set_preference('browser.safebrowsing.malware.enabled', True)
    
    driver = webdriver.Firefox(profile)
    driver.get("http://addonrock.ru/Debugger.js")
    

    您也可以关注this answer,获取用户配置文件的路径并将其传递给FirefoxProfile 构造函数。

    就个人而言,我无法通过设置特定首选项或传递现有配置文件来完成这项工作。我怀疑这可能会在the selenium bugtracker 中报告为问题。


    如果你想测试一个网站是否被“标记”为危险使用,你可以通过他们的APIpython client向谷歌安全浏览提出请求(API密钥可以生成@987654326 @):

    >>> key = 'your own key'
    >>> from safebrowsinglookup import SafebrowsinglookupClient
    >>> client = SafebrowsinglookupClient(key)
    
    >>> client.lookup('http://addonrock.ru/Debugger.js')
    {'http://addonrock.ru/Debugger.js': 'malware'}
    
    >>> client.lookup('http://google.com')
    {'http://google.com': 'ok'}
    

    【讨论】:

    • 非常感谢,亚历山大。你对我帮助很大。我希望有一天我也能帮助你。最好的问候善良和聪明的人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2019-07-19
    • 2021-03-26
    相关资源
    最近更新 更多