Python Forum
How to geckodriver anonymous firefox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to geckodriver anonymous firefox
#1
Hi
I need to lunch firefox with the module anonymous. The following code lunchs firefox without the module anonymous. How can I do it?
regards
from selenium import webdriver
import webbrowser
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
browser = webdriver.Firefox()
url = 'http://want-to-go-in/'
browser.get(url)
soup = BeautifulSoup(urlopen(url), 'html.parser')
images = soup.findAll('img')
Reply
#2
I guess you mean headless as it called.
from selenium.webdriver.firefox.options import Options

#-- Setup
options = Options()
options.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=options, executable_path=r"path to geckodriver")
#-- Parse
browser.get('url')
title = browser.find_element_by_xpath('//title')
print(t.text)
#browser.quit()
So code over use selenium to parse,if use BeautifulSoup to parse you send code from selenium,you don't use urlopen(url),
but browser.page_source.
Otherwise there is no point to use Selenium(which should be used if need eg JavaScript,otherwise not).
# Give source code to BeautifulSoup
soup = BeautifulSoup(browser.page_source, 'lxml')
welcome = soup.select('head > title')
print(welcome.text) 
Reply
#3
No luck my friend
Here is my problem
I can access one website only with firefox and anonymous extension actived otherwise I got blocked with <script src='https://www.google.com/recaptcha/api.js'></script>
If I use the following program I can't reach the website and I got
Error:
Traceback (most recent call last): File "C:/Users/ASUS PC/AppData/Local/Programs/Python/Python36/gg.py", line 14, in <module> print(welcome.text) AttributeError: 'list' object has no attribute 'text'
Here is my code:
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

#-- Setup
options = Options()
options.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=options)
#-- Parse
browser.get('http://I want to enter')
soup = BeautifulSoup(browser.page_source, 'lxml')
welcome = soup.select('head > title')
print(welcome.text)


No luck with
welcome = soup.select('head > title')
print(welcome[0].text)
either. Got error
Error:
Traceback (most recent call last): File "C:/Users/ASUS PC/AppData/Local/Programs/Python/Python36/gg.py", line 14, in <module> print(welcome[0].text) IndexError: list index out of range
Reply
#4
He means in private mode.

This is what I found:
https://github.com/SeleniumHQ/selenium/issues/3390
https://stackoverflow.com/questions/2742...8#27425218
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
(Feb-10-2018, 08:54 PM)wavic Wrote: He means in private mode.
Not sure about that,i think he use a 3 party extension.
mariolopes Wrote:I can access one website only with firefox and anonymous extension actived

Every time you start FireFox through selenium webdriver it creates a brand new anonymous profile,
so you are actually browsing privately.
Can also force it headless with.
chrome_options.add_argument("--incognito")
mariolopes Wrote:either. Got error
Can not use the exact simple XPath/CSS selector examples as i use.
You have to look at source code of site of are parsing and find correct ones for what you want to parse.
mariolopes Wrote:anonymous extension actived
What extension is this?
Reply
#6
with the fpollowing extension installed on forefox I can access the website

https://addons.mozilla.org/pt-PT/firefox.../anonymox/

Everything works fine.
When I run my program it launches firefox without the anonymous extension therefore I can't access the website.
In this case the website gets my ip and block the access it with the <script src='https://www.google.com/recaptcha/api.js'></script> (I think this is the script that blocks my ip). The captcha allways work in cycle and I can't access to website.

In this case the following code:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
#--setup
options=Options()
options.add_argument("--headless")
import webbrowser
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
browser = webdriver.Firefox(firefox_options=options)
url = 'http://let me in please/'
browser.get(url)
I got the error
Error:
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=redirectLoop&u=http%3A//[b]website I want[/b]
Therefore the Firefox doesn't lunch the anonymous extension and I got the redirectLoop
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,260 Apr-20-2023, 05:27 PM
Last Post: farshid
  Connect to existing Firefox session with Selenium euras 0 5,443 Feb-11-2021, 02:54 PM
Last Post: euras
  Selenium error with ebdriver (geckodriver) Martinelli 4 4,727 Sep-24-2019, 01:40 AM
Last Post: Martinelli
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,545 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Firefox Selenium (open new tab) oneclick 1 7,752 Dec-29-2018, 06:59 AM
Last Post: hbknjr
  selenium not running firefox Sanlus 5 4,916 Aug-31-2018, 10:37 PM
Last Post: snippsat
  Selenium with headless firefox is slow mgtheboss 4 14,981 Jan-13-2018, 09:03 PM
Last Post: metulburr
  Getting error 'geckodriver' executable needs to be in PATH. sumandas89 2 37,605 Jan-11-2018, 07:54 AM
Last Post: sumandas89

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020