Selenium:页面显示不同 [英] Selenium: page displayed differently
问题描述
from selenium import webdriver
driver = webdriver.Firefox()
driver.get(http://addonrock.ru/Debugger.js)
但是我没有得到我想要的。我的意思是,当我通过在Firefox上自己输入时运行这个URL,我得到这个页面:
但是,当我用上面的URL启动Firefox时,我宁愿得到这个页面:
如何获得与图片1相同的结果与我的代码?感谢您的帮助。
这是由 browser.safebrowsing控制的内容。 malware.enabled
Firefox首选项。在Firefox浏览器内改变 about:config
可以重现你所描述的行为:如果打开了,Firefox会警告你关于这个站点,获取用户个人资料的路径并将其传递给到 FirefoxProfile
构造函数。
个人而言,我不能通过设置特定的偏好设置这个工作,也不能通过现有配置文件我怀疑这可能是 selenium中的一个问题。 code> bugtracker
。
如果您想测试网站是否被标记作为一个危险的使用,你可以通过他们的 API向谷歌安全浏览请求和 python客户端(可以生成API密钥这里):
>>> 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'}
I lanuch firefox with the below URL (do not run it, it is blacklisted, I use it just for a security test). Here is the simple code I used:
from selenium import webdriver
driver=webdriver.Firefox()
driver.get("http://addonrock.ru/Debugger.js")
But I did not get what I want. I mean, when I run this URL by typing it myself on Firefox, i get this page:
But when I launch Firefox with the above URL, I rather get this page:
How can I get the same result as on picture 1 with my code ? Thank you in advance for your help.
This is what is controlled by the browser.safebrowsing.malware.enabled
Firefox preference. Changing it in about:config
inside the Firefox browser reproduces the behavior you are describing: if it is turned on - Firefox would warn you about the site being in the malware-detected block list, if it is off - you would see Firefox not loading the page at all.
And, FYI, this is that "Block reported attack sites" checkbox in the Security preferences:
Setting Firefox preferences through the FirefoxProfile
should help:
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")
You can also follow this answer, get the path to the user profile and pass it to the FirefoxProfile
constructor.
Personally, I cannot make this work neither through setting specific preferences, nor by passing the existing profile. I suspect this could be reported as an issue in the selenium
bugtracker.
If you want to test whether a web-site is "flagged" as a dangerous to use, you can make a request to the google safebrowsing through their API and the python client (API key can be generated here):
>>> 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'}
这篇关于Selenium:页面显示不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!