user3522371
user3522371

Reputation:

Selenium: page displayed differently

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:


enter image description here

But when I launch Firefox with the above URL, I rather get this page:

enter image description here

How can I get the same result as on picture 1 with my code ? Thank you in advance for your help.

Upvotes: 1

Views: 510

Answers (1)

alecxe
alecxe

Reputation: 473813

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: firefox security prefences

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'}

Upvotes: 3

Related Questions