Python Forum
Proxy Variable in Selenium wont work with FireFox Profile Proxy Setting.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Proxy Variable in Selenium wont work with FireFox Profile Proxy Setting.
#1
edited for clarity:
Python Selenium Passing Scraped Proxy .text object Variable to Firefox Profile? I can get the proxy working with a string as the proxy but not the selenium text object scraped from the proxy website. I'm Still getting my local IP when passing the Selenium .text object. I can't understand why this isn't passing the proxy that is being printed in terminal as the variable for the proxy? I've included the code below with some of the solutions I've tried commented out.

Any help is much appreciated. I've been working on this project for way to long.

###############################################################################
#   MIPYTHON .com Python PROXY SCRAPE and GO SCRIPT in SELENIUM
###############################################################################
from selenium import webdriver
import time
print("*" * 60)
print("MIPYTHON .com Python PROXY SCRAPE and GO SCRIPT in SELENIUM")
print("*" * 60)

browser = webdriver.Firefox()
proxy_website = "https://free-proxy-list.net/"
target_website = "https://icanhazip.com"   #"https://www.whatismyip.com"
###   SCRAPE PROXY
browser.get(proxy_website)
browser.find_element_by_xpath('/html/body/header/div[1]/div/div[1]/div/div/a[2]').click()
proxy = browser.find_element_by_xpath('/html/body/section[1]/div/div[2]/div/div[2]/div/table/tbody/tr[1]/td[1]').text
print(proxy)
proxy_port = browser.find_element_by_xpath('/html/body/section[1]/div/div[2]/div/div[2]/div/table/tbody/tr[1]/td[2]').text
print(proxy_port)
###   USE PROXY
#proxy = "89.23.19.143"
#proxy_port = 8080
#proxy = int(proxy)
#proxy_port = int(proxy_port)
#proxy = str(proxy)
#proxy_port = str(proxy_port)
proxy_profile = webdriver.FirefoxProfile()
proxy_profile.set_preference("network.proxy.type", 1)
proxy_profile.set_preference("network.proxy.http", proxy )
proxy_profile.set_preference("network.proxy.http_port", proxy_port)
proxy_profile.set_preference("network.proxy.ssl", proxy )
proxy_profile.set_preference("network.proxy.ssl_port", proxy_port)
browser = webdriver.Firefox(firefox_profile=proxy_profile)
target_website = browser.get(target_website)
edit again:

Ok found the answer here from
Running Selenium Webdriver with a proxy in Python @erm3nda
solution is this. Port has to be an integer the proxy can apparently be a string.
proxy_port = int(proxy_port)
proxy = str(proxy)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using a Proxy Server rsherry8 12 24,395 Dec-04-2023, 06:35 PM
Last Post: AlluminumFoil
  How to profile tornado web app ? umen 2 919 Oct-09-2023, 05:59 PM
Last Post: noisefloor
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,214 Apr-20-2023, 05:27 PM
Last Post: farshid
  Connect to existing Firefox session with Selenium euras 0 5,388 Feb-11-2021, 02:54 PM
Last Post: euras
  how to add proxy authentication selenium farhan275 10 15,233 Sep-10-2020, 10:18 PM
Last Post: farhan275
  Open URL via proxy perseus142 2 6,686 Jun-18-2020, 10:48 PM
Last Post: micseydel
  Python-selenium script for automated web-login does not work hectorKJ 2 3,983 Sep-10-2019, 01:29 PM
Last Post: buran
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,501 Aug-04-2019, 11:10 AM
Last Post: pjn4
  RelatedObjectDoesNotExist: User has no profile. Django 1.11 m0ntecr1st0 1 12,503 Feb-21-2019, 01:00 AM
Last Post: m0ntecr1st0
  Firefox Selenium (open new tab) oneclick 1 7,695 Dec-29-2018, 06:59 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

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