5

Need use random userAgent. My code it is:

#!/usr/bin/python
# Import selenium
from selenium import webdriver

# init Profile options for navigation
fp = webdriver.FirefoxProfile()

# Set userAgent
fp.set_preference("general.useragent.override", "custom userAgent")
fp.update_preferences()

1 Answer 1

7

I personally use the fake-useragent library.

You can generate random useragents with:

from fake_useragent import UserAgent
from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.set_preference("general.useragent.override", UserAgent().random)
fp.update_preferences()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.