I am trying to login to the blogger site, but first I have to enter the Gmail account. I entered it, but an error message appears, "This browser or app may not be secure" can you help me with this error. this is my code
from statistics import mean
import pandas as pd
from selenium_stealth import stealth
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import pyautogui
import time
print("ready?")
print("loading.......................................")
df = pd.read_excel("Moaaz.xlsx","Moaaz")
email = "[email protected]"
password = "1*1#36@$%anz"
name = df["Name"].values.tolist()
website = df["Website"].values.tolist()
phone = df["Phone"].values.tolist()
logo = df["Logo"].values.tolist()
firm_map = df["Firm map"].values.tolist()
driver = webdriver.Chrome("D:\\driver\\chromedriver.exe")
driver.delete_all_cookies()
driver.get('https://www.blogger.com/blog/posts/3793019451239403430')
time.sleep(2)
driver.maximize_window()
time.sleep(2)
driver.find_element_by_id('identifierId').send_keys(email)
time.sleep(3)
driver.find_element_by_id('identifierNext').click()
time.sleep(3)
driver.find_element_by_id('password').send_keys(password)
time.sleep(2)
driver.find_element_by_id('passwordNext').click()
time.sleep(10)
for s in range(len(name)):
#click new post
driver.find_element_by_class_name('U26fgb O0WRkf zZhnYe e3Duub C0oVfc zr7Fj zFM5pd M9Bg4d').click()
#enter name dog
driver.find_element_by_class_name('whsOnd zHQkBf').send_keys(name[s])
#convert to html view
pyautogui.leftClick(627, 707)
pyautogui.leftClick(455, 206)
pyautogui.leftClick(149, 279)
driver.stop_client()
CodePudding user response:
You need to disable the web security with adding some options to your driver.
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--disable-web-security")
options.add_argument("--allow-running-insecure-content")
driver = webdriver.Chrome("D:\\driver\\chromedriver.exe",options = options)
driver.get('https://www.blogger.com/blog/posts/3793019451239403430')
CodePudding user response:
You can use undetected-chromedriver, also works for cloudflare bypass and google login
pip install undetected-chromedriver
Your optimized code with undetected-chromedriver
, WebdriverWait
and By.
import pandas as pd
import pyautogui
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
print("ready?")
print("loading.......................................")
df = pd.read_excel("Moaaz.xlsx","Moaaz")
email = "[email protected]"
password = "1*1#36@$%anz"
name = df["Name"].values.tolist()
website = df["Website"].values.tolist()
phone = df["Phone"].values.tolist()
logo = df["Logo"].values.tolist()
firm_map = df["Firm map"].values.tolist()
driver = uc.Chrome(use_subprocess=True)
wait = WebDriverWait(driver, 15)
driver.delete_all_cookies()
driver.get('https://www.blogger.com/blog/posts/3793019451239403430')
driver.maximize_window()
wait.until(EC.visibility_of_element_located((By.ID, 'identifierId'))).send_keys(email)
wait.until(EC.visibility_of_element_located((By.ID, 'identifierNext'))).click()
wait.until(EC.visibility_of_element_located((By.ID, 'password'))).send_keys(password)
wait.until(EC.visibility_of_element_located((By.ID, 'passwordNext'))).click()
for s in range(len(name)):
#click new post
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'U26fgb O0WRkf zZhnYe e3Duub C0oVfc zr7Fj zFM5pd M9Bg4d'))).click()
#enter name dog
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'whsOnd zHQkBf'))).send_keys(name[s])
#convert to html view
pyautogui.leftClick(627, 707)
pyautogui.leftClick(455, 206)
pyautogui.leftClick(149, 279)
driver.stop_client()