I am using Python selenium chromedriver and I want to add Capmonster to my code. Basically if my Code gets the URL, a ReCaptcha appears and I want to get it solved.
My Code
from threading import Thread
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import os
chromedriver = 'C:\\Users\\yvesb\\OneDrive\\Desktop\\chromedriver\\chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
def test(driver, url):
driver.get(url)
try:
driver.save_screenshot('C:\\Users\\yvesb\\Downloads\\headless_chrome_test7.png')
finally:
print("screenshot done")
url = "https://www.snipes.com/login"
Thread(target=test, args=(driver, url)).start()
And when it gets the URL a ReCaptcha appears, which I want to get solved with my Capmonster Key.
I suggest you to try this library I've developed some time ago. If you have a set of labelled captchas that service would fit you. Take a look: https://github.com/punkerpunker/captcha_solver
In README there is a section "Train model on external data" that you might be interested in.
Related
I'm trying to change my code to use an IE headless browser. The automation I'm doing is in a website that only works in internet explorer
My code was working great until I tried to use a headless browser
When I run this code, absolutely nothing happens, no error is thrown
# selenium 4
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager
from selenium.webdriver.ie.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException
from dotenv import load_dotenv
# Inicialização do Selenium
ie_options = Options()
ie_options.ignore_zoom_level = True
## WORKS!
# driver = webdriver.Ie(service=Service(IEDriverManager().install()), options=ie_options)
## NOT WORKING
service = Service(executable_path=constantes.PATH_HEADLESS)
driver = webdriver.Ie(service=service, options=ie_options)
# Acessa a página
driver.get(constantes.URL)
I believe the reason why it seems nothing is happening is because you have no output (not printing anything). I'm not familiar with your process, but I tried it out with mine also using chrome and it worked fine. Context:
chrome_options = Options()
chrome_options.add_argument("--headless")
driver=webdriver.Chrome(service=Service('*executable
path'),options=chrome_options)
driver.get('https://stackoverflow.com/')
print(driver.title)
someone of you, can close the first modal on the website of flight company easyjet, accepting the cookie policy?
i tryed in many way but never closed it
this is my code
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import os
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.easyjet.com/it")
time.sleep(2)
#chiudi cookie
cookie = driver.find_element(By.id,"ensCloseBanner")
cookie.click()
time.sleep(2)
I believe it's a typo. instead of id it should be ID
cookie = driver.find_element(By.ID,"ensCloseBanner")
Reference link : Selenium python locator
I had this issue on 2 different systems, on first PC it went away after a reboot, on the other it had not gone away
Below is a portion of the code in question:
I masked some things on purpose
The edge browser is stuck on openign page with data;, shown in the address bar. It does not go beyond this.
I checked that Edge and Edgedriver are the same exact version, if it matters.
I cannot use Chrome or any other drivers for this project
Why doesn't selenium advance past the opening of the program?
I also have an error in CMD when it launches: [9704:11992:0305/080544.278:ERROR:storage_reserve.cc(164)] Failed to open file to mark as storage reserve: C:\Users**\AppData\Local\Temp\scoped_dir3468_1483298328\Default\Code Cache\js on selenium
How do I fix this?
# importing required package of webdriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\Users\*****\Desktop\msedgedriver.exe")
sleep(2)
browser.maximize_window()
sleep(2)
browser.get('https://********/) #masked the name of website on purpose
try:
# Get the text box to insert Email using selector ID
myElem_1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'anti-myhub')))
sleep(3)
# Entering the email address
myElem_1.click()
I want to attach file through below link. How can I do that using selenium python?
My code:
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
driver=webdriver.Chrome(executable_path="C:\Program Files (x86)\Drivers\chromedriver.exe")
driver.get("https://www.tascoutsourcing.com/job-openings/quality-assurance-engineer/")
driver.maximize_window()
time.sleep(10)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
driver.find_element_by_xpath("//*[#id='content']/div[2]/div[2]/div/div/div/div[1]/div/div/div/button").click()
driver.find_element_by_xpath("//*[#id='content']/div[2]/div[2]/div/div/div/section/div/form/div[3]/div[3]/div").click()
paul, please try to run below code - I have ran the same code in my system and it is working for me.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
action = ActionChains(driver)
driver.get("https://www.tascoutsourcing.com/job-openings/quality-assurance-engineer/")
# Click on Apply Button
Apply_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Apply Now']/parent::button")))
action.move_to_element(Apply_btn).click().perform()
time.sleep(2)
Upload_File = driver.find_element_by_xpath('/html/body/label/input').send_keys("YourFilePath")
Do let me know if it shows error.
I am having problems with my selenium script.
I want to webscrape a website that is running on javascript.
I have been gathering a lot of information on the internet but i can't find the solution.
picture of the html code
picture of my code
In this post i have also submitted a printscreen of the HTML code.
Basically: i want click on the accept button when i load the website but i can't figure how to do this.
searching on different websites for the solution.
Can you guys help me with my script, i have been trying and testing a lot but i can't figure it out.
thank you.
code:
from config import keys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
def order(k):
chrome_path =
r"C:\Users\ltewo\PycharmProjects\livebetting\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get(keys['url'])
xpath_button_accept = "//div[#class='cookieButtons']//a[#class='button
accept']"
button_accept = driver.find_element_by_xpath(xpath_button_accept)
xpath_button_accept.click()
if __name__ == '__main__':
order(keys)
You should wait for that element to load on the page, so use:
WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.XPATH, 'XpathOfMyElement')))
I noticed that the cookie panel was inside an iframe and was not directly accessible, I have updated the below, please check it's working now.
Updated your code:
from config import keys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
def order(keys):
chrome_path = r"C:\Users\ltewo\PycharmProjects\livebetting\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get(keys['url'])
driver.switch_to.frame('r42CookieBar')
button_accept = driver.find_element_by_class_name('accept')
button_accept.click()
if __name__ == '__main__':
order(keys)
Try this:
#update
driver.implicity_wait(10)
xpath_button_accept = "//div[#class='cookieButtons']//a[#class='button accept']"
button_accept = your_browser.find_element_by_xpath(xpath_button_accept)
button_accept.click()