Selenium: Follow adfly redirect - python

Im trying to make a bot that visits my adfly link using the chrome webdriver. Every time I try to use the code below though, the webdriver tells me that there were too many redirects and doesn't follow through. The code below is just being used for testing at the moment:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"http://102.129.249.120:8080")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")
Image of error here

Okay so i figured it out. I can use tor with selenium to get access to adfly. Works great btw. Thanks for the help and time guys. If you want to see the code I used, here it is:
from selenium import webdriver
import os
os.popen(r'C:\Users\joldb\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server="+"socks5://127.0.0.1:9050")
browser = webdriver.Chrome(options=options)
browser.get("http://raboninco.com/18Whc")

Related

I tried to open the site with this code using selenium, but the site was closed as soon as it was opened

When I run this code, the page opens and closes. I can't reach the page. Everything is in the latest version. I am a Windows user.
I was trying to open Instagram page with this code.
enter image description here
I tried to open the instagram site with this code and the site was closed as soon as it was opened.
Im not familiar with selenium but I know for a fact that
get() just gets the HTML code of the website and does not display it
You have to add the below Chrome Option:
options.add_experimental_option("detach", True)
Full code:
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(chrom_driver_pat), options=options)
driver.get(<url>)
Next time, don't post the image, post the code and explain your issue clearly.
First of all, please, do not use images when your want a code review or help, it is more easier to help with raw code.
Selenium now uses Service method to run webdriver.
To run what you want, you need to fix some parts of your code, like this:
from selenium import webdriver
# in my case, i'm using selenium==4.5.0, for this version, is necessary to
# use selenium.webdriver.chrome.service to use driver path
from selenium.webdriver.chrome.service import Service as ChromeService
# For Windows path, use r"C:\..." when you will use \
# Remember to set the executable file too
chrome_driver_path = r"C:\pythondriver\chromedriver\chromedriver.exe"
# you can use "universal" path too, like linux, using / instead of \
# chrome_driver_path = "C:/pythondriver/chromedriver/chromedriver.exe"
# instead using:
# webdriver.Chrome()
# driver = webdriver.Chrome(chrome_driver_path)
# use this:
chrome_service = ChromeService(chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service)
url = "https://instagram.com"
driver.get(url)
I tested using the configurations below and worked for me:
Chromedriver - 108.0.5359.71
Chrome - 108.0.5359.125 - 64 bits
If you need more help using Chrome Service, try look the Selenium Docs

Prevent Safari from closing in Mac using Selenium Python?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
safari_option = Options()
safari_option.add_experimental_option("detach", True)
# Prevent closing browser after done execution
driver = webdriver.Safari(options=safari_option)
driver.get("https://www.google.com/?client=safari")
elem = driver.find_element(By.NAME, "q")
elem.clear()
elem.send_keys("test")
I want to prevent safari from closing after the webdriver has finished so that I can see the process of automating another website clearly one by one.
I tried using the safari_option.add_experimental_option("detach", True)
as has been done here
Python selenium keep browser open
for chrome. But I'm not quite sure why it did not work for Safari instead.Seems like a simple problem but couldn't find an answer for it on google or maybe Im blind. Im pretty new to Selenium btw.
Thanks

Python Selenium Edge Webdriver doesn't open the Website

that's the first time I work with Selenium and I got the problem that I can't open a Website in Edge using Selenium.
from selenium import webdriver
driver = webdriver.Edge(executable_path="/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")
url = "https://www.google.com/"
driver.get(url)
Please help me as fastest as possible. Thank you.

Python chrome opens with “Data;” with selenium

I am using python selenium for web scraping, but after running the below codes, chrome is launched but did not get the website as I want, instead, it shows 'data;' in url bar.
Could anyone help with the problem? Many thanks!!
PS: My chrome is 88.and chromedriver is also 88. the path of chrome and chromedriver are different, one is in desktop and the other is C://
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import random
option = Options()
option.add_experimental_option('excludeSwitches', ['enable-logging'])
option.add_argument('--remote-debugging-port=9222')
driver =webdriver.Chrome(executable_path='C:/Users/Desktop/chromedriver.exe')
driver.get("https://www.youtube.com")
Instead of using this
from selenium.webdriver.chrome.options import Options
options = options()
use this
options = webdriver.ChromeOptions()
and I would suggest you to put everything in the same project directory. which is a best practice.
Once you've put the chromedriver in the same directory.
do this:
from os import getcwd
driver = webdriver.Chrome(getcwd() + "\chromedriver.exe", options=options)
Also, try to close the old chrome windows.
It will go to data:// and after that it will redirect to your website.
And also follow Jiya's answer as well.

How to open url with selenium webdriver python with differents IPs?

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=125.62.213.229:82')
browser = webdriver.Chrome(executable_path='F:\Drivers\ChromeDriver\chromedriver.exe', chrome_options=options)
browser.get("http://www.whatismyipaddress.com")
I dont know to apply loop in this.
using .format to substitute.
ip=['125.62.213.229:82'] # add others here.
for i in ip:
options.add_argument(('--proxy-server={0}').format(i))
#rest of your code

Categories