Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

PhantomJS useragent

I am using PhantomJS with selenium and I am trying to change the user-agent, but it will not change. I studied the selenium code, and trying to change the headers, but nothing works. Does anybody have a solution?
(Jan 13, 2019 04:14 PM)FW1738 Wrote:  I am using PhantomJS with selenium and I am trying to change the user-agent, but it will not change. I studied the selenium code, and trying to change the headers, but nothing works. Does anybody have a solution?

I usually use firefox or chrome with the headless option instead of phantomjs (during the years python support has been dropped often)

Anyway can you try this code:

Code
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
"(KHTML, like Gecko) Chrome/15.0.87")

driver = webdriver.PhantomJS(desired_capabilities=dcap)
(Jan 14, 2019 03:20 AM)FriendZone Wrote:  I usually use firefox or chrome with the headless option instead of phantomjs (during the years python support has been dropped often)

Since when do Chrome and Firefox have headless options?
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Jan 14, 2019 07:59 AM)lockhead Wrote:  Since when do Chrome and Firefox have headless options?

Since always ahah

No, I’ m not sure when, but since years

In few mins I will post firefox headless
(Jan 14, 2019 08:13 AM)FriendZone Wrote:  Since always ahah

No, I’ m not sure when, but since years

In few mins I will post firefox headless

Damn.. it's been a while since I needed something like this but a few years ago I had to deal with this PhantomJS BS because apparently it was the only option...
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Jan 14, 2019 08:16 AM)lockhead Wrote:  Damn.. it's been a while since I needed something like this but a few years ago I had to deal with this PhantomJS BS because apparently it was the only option...

Code
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

binary = FirefoxBinary(‘BINARY PATH’)
options = Options()
options.set_headless(True)

driver = webdriver.Firefox(options=options, exacutable_path=‘GECKODRIVER PATH’ , firefox_binary=binary)

driver.browser.get(‘https://www.google.com’)


N.B.

I wrote the code without a pc close to me to test it .

Keep in mind firefox is slower than chrome in headless mode (I read time ago a speed test article about it)

Switch BINARY PATH and GECKODRIVER PATH with the right paths tell me if you need help
(Jan 14, 2019 03:20 AM)FriendZone Wrote:  I usually use firefox or chrome with the headless option instead of phantomjs (during the years python support has been dropped often)

Anyway can you try this code:

Code
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
"(KHTML, like Gecko) Chrome/15.0.87")

driver = webdriver.PhantomJS(desired_capabilities=dcap)


Doesn't work for me. When I print the navigator.userAgent, I still get the same. I got phantomjs version 2.1.1, think that is the newest. That shouldn't be the problem. Does the code work for you?
(Jan 14, 2019 09:24 AM)FW1738 Wrote:  Doesn't work for me. When I print the navigator.userAgent, I still get the same. I got phantomjs version 2.1.1, think that is the newest. That shouldn't be the problem. Does the code work for you?

As stated I don’t use phantomjs but firefox, so I didn’t test it, as soon I will be at home I will find a working way if possible :)
(Jan 14, 2019 09:27 AM)FriendZone Wrote:  As stated I don’t use phantomjs but firefox, so I didn’t test it, as soon I will be at home I will find a working way if possible :)

Thank you, do you know if firefox gets detected easily by for example recaptcha?
(Jan 14, 2019 09:30 AM)FW1738 Wrote:  Thank you, do you know if firefox gets detected easily by for example recaptcha?

I would play with profiles and proxies.

Do you need an example to set it in firefox?
No I know selenium pretty good, but I thought maybe you knew ways to detect the firefox driver besides the easy ones such as the navigator.webdriver flag.
I must add that running chrome headless vs firefox is a much greater gain if your looking for as little resource usage as possible.

Headless firefox and the non-headless version aren't that different in resource consumption, where as chrome is 30% less than it's non-headless version.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Roblox_BTCApr 18, 2018 05:32 PM 4 456 Apr 18, 2018 05:32 PM
Last Post: r0binho0d44
[Java] by milknpepperFeb 10, 2018 10:04 AM 3 144 Feb 10, 2018 10:04 AM
Last Post: V3t3r4n
[Java] by milknpepperFeb 10, 2018 04:36 AM 0 120 Feb 10, 2018 04:36 AM
Last Post: milknpepper