我对Google登录有疑问。我想登录到我的帐户,但是Google表示不允许自动化驱动程序登录。
我正在寻找解决方案。是否可以获取普通Firefox / Chrome的Cookie并将其加载到ChromeDriver / GeckoDriver中?我认为这可以解决。但我不确定是否可能。
寻找解决方案。
此外,我想为此添加一个快速解决方案。我解决了这个问题 使用我的旧的已验证帐户之一。那可能是一个快速的解决方案 你也是。
答案 0 :(得分:4)
一个对我有用的解决方案:https://stackoverflow.com/a/60328992/12939291或https://www.youtube.com/watch?v=HkgDRRWrZKg
简短:使用重定向的Google帐户登录Stackoverflow
from selenium import webdriver
from time import sleep
class Google:
def __init__(self, username, password):
self.driver = webdriver.Chrome('./chromedriver')
self.driver.get('https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent%27')
sleep(3)
self.driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click()
self.driver.find_element_by_xpath('//input[@type="email"]').send_keys(username)
self.driver.find_element_by_xpath('//*[@id="identifierNext"]').click()
sleep(3)
self.driver.find_element_by_xpath('//input[@type="password"]').send_keys(password)
self.driver.find_element_by_xpath('//*[@id="passwordNext"]').click()
sleep(2)
self.driver.get('https://youtube.com')
sleep(5)
username = ''
passwort = ''
Google(username, password)
答案 1 :(得分:3)
这可能仍处于打开状态/未回答
这是以下线程中的一个工作 (28.04.2021) 示例: https://stackoverflow.com/a/66308429/15784196
使用 Firefox 作为驱动程序。我测试了他的例子,它确实有效!
答案 2 :(得分:2)
此错误消息...
...表示 WebDriver 实例无法认证浏览上下文,即 Browser 会话。
此错误可能是由于以下多种因素引起的:
在文章"This browser or app may not be secure" error when trying to sign in with Google on desktop apps中,@ Raphael Schaad提到,如果用户可以使用其他Google帐户登录就可以正常登录同一应用,那么问题一定出在特定帐户上。在大多数情况下,可能的原因是,此特定用户帐户配置了双重身份验证。
在文章Less secure apps & your Google Account中提到,如果某个应用或网站不符合google-chrome的security standards,Google可能会阻止尝试登录的任何人从它到您的帐户。安全性较低的应用程序可能使黑客更容易进入您的帐户,因此阻止这些应用程序的登录有助于确保您的帐户安全。
在这些情况下,相应的解决方案是:
中找到详细的讨论
但是,为了保护您的帐户,网络浏览器可能不允许您使用某些浏览器登录。 Google可能会停止从以下浏览器登录:
在这些情况下,有多种解决方案:
使用支持 JavaScript 的浏览器:
Chrome
Safari
Firefox
Opera
Internet Explorer
Edge
在 Web浏览器中打开JavaScript:如果您使用的是受支持的浏览器,但仍然无法登录,则可能需要打开JavaScript。
如果您仍然无法登录,可能是因为您打开了 AutomationExtension / 不安全 / 不受支持的扩展并且您可能需要关闭以下内容:
public class browserAppDemo
{
public static void main(String[] args) throws Exception
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(options);
driver.get("https://accounts.google.com/signin")
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("gashu");
driver.findElement(By.id("identifierNext")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("gashu");
driver.findElement(By.id("passwordNext")).click();
System.out.println(driver.getTitle());
}
}
您可以在以下位置找到一些相关的讨论:
Selenium test scripts to login into google account through new ajax login form
最后,某些旧版本的浏览器可能不受支持,因此请确保:
答案 3 :(得分:2)
我遇到了同样的问题,并找到了解决方案。我正在使用
1)Windows 10专业版
2)Chrome版本 private PendingIntent registerAlarm(int hour, int minute, int id){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
intent.putExtra("NAME",id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, id, intent,0);
AlarmManager am = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
System.out.println("SELAMLAR OLSUN ID MAIN: " + id);
return pendingIntent;
}
private void cancelAlarm(int RSQ) {
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RSQ, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
}
3)硒ChromeDriver public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent("com.demo.FirebaseMessagingReceiveService");
notificationIntent.setClass(context, Main2Activity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int id = Integer.valueOf(intent.getStringExtra("NAME"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification.Builder builder = new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_android_black_24dp)
.setContentTitle("ONLINE QUIZ APP")
.setContentText("HEY TRY TO SOLVE TODAY")
.setSound(alarmSound)
.setAutoCancel(true)
.setWhen(when)
.setContentIntent(pendingIntent)
.setVibrate(new long[] {1000, 1000, 1000, 1000, 1000});
context.startService(notificationIntent);
notificationManager.notify(id, builder.build());
}
一些打开Google页面的简单C#代码
83.0.4103.97 (Official Build) (64-bit)
这里的核心问题使用硒驱动程序时无法登录,但是可以使用已经登录到google帐户的配置文件。
您必须找到您的Chrome商店个人资料的位置,并使用83.0.4103.39
选项将其附加。
PS。将{username}替换为您的真实帐户名。
在Linux上,用户个人资料位于var options = new ChromeOptions();
options.addArguments(@"user-data-dir=c:\Users\{username}\AppData\Local\Google\Chrome\User Data\");
IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver();
driver = new ChromeDriver(Directory.GetCurrentDirectory(), options);
driver.Url = "https://accounts.google.com/";
Console.ReadKey();
中。
答案 4 :(得分:2)
我找到了一个解决方案,@theycallmepix 和@Yinka Albi 是正确的,但因为(我认为)谷歌黑名单帐户第一次以编程方式登录,所以后来他们无法正常登录。 所以基本上只需使用不同的帐户并转到 Stackauth 或 StackoverFlow。然后手动登录谷歌(首先链接您的帐户)然后手动登录google.com,然后它应该可以正常工作
附言如果这不起作用,请发表评论
答案 5 :(得分:1)
经过数小时的反复试验,我只是尝试了一些对我有用的东西。
将args: ['--disable-web-security', '--user-data-dir', '--allow-running-insecure-content' ]
添加到我的配置中解决了该问题。
后来我意识到,这不是帮助我的原因,因为我尝试使用另一封电子邮件,但没有用。经过一些观察,我发现其他问题,并且已经尝试和测试了。
使用自动化:
转到https://stackoverflow.com/users/login 选择使用Google策略登录 输入Google用户名和密码 登录到Stackoverflow 转到https://gmail.com(或您要访问的任何Google应用)
在一整天(大约24小时)内持续进行此操作后,尝试直接将您的登录信息直接自动自动直接登录gmail(或您要访问的任何Google应用)...我至少有两个人这样做成功。 PS-您可能要继续进行stackoverflow登录,直到我们都经历了该阶段为止,至少收到验证码请求。
答案 6 :(得分:1)
使用下面给出的代码段method
登录到您的Google帐户。
语言:Python3
重定向通过:StackAuth(原因在最后解释)
[编辑: 您需要导入所需的软件包。确保您执行的自动化在Foreground中运行,我的意思是,直到您完全登录后,它才会被最小化。如果登录成功,则可以重定向到所需的所需网站。]
def login(username, password): # Logs in the user
driver.get('https://accounts.google.com/o/oauth2/auth/identifier?client_id=717762328687-iludtf96g1hinl76e4lc1b9a82g457nn.apps.googleusercontent'
'.com&scope=profile%20email&redirect_uri=https%3A%2F%2Fstackauth.com%2Fauth%2Foauth2%2Fgoogle&state=%7B%22sid%22%3A1%2C%22st%22%3A%2'
'259%3A3%3Abbc%2C16%3A561fd7d2e94237c0%2C10%3A1599663155%2C16%3Af18105f2b08c3ae6%2C2f06af367387a967072e3124597eeb4e36c2eff92d3eef697'
'1d95ddb5dea5225%22%2C%22cdl%22%3Anull%2C%22cid%22%3A%22717762328687-iludtf96g1hinl76e4lc1b9a82g457nn.apps.googleusercontent.com%22%'
'2C%22k%22%3A%22Google%22%2C%22ses%22%3A%2226bafb488fcc494f92c896ee923849b6%22%7D&response_type=code&flowName=GeneralOAuthFlow')
driver.find_element_by_name("identifier").send_keys(username)
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, "//*[@id='identifierNext']/div/button/div[2]"))).click()
driver.implicitly_wait(4)
try:
driver.find_element_by_name("password").send_keys(password)
WebDriverWait(driver, 2).until(expected_conditions.element_to_be_clickable((By.XPATH, "//*[@id='passwordNext']/div/button/div[2]"))).click()
except TimeoutException:
print('\nUsername/Password seems to be incorrect, please re-check\nand Re-Run the program.')
del username, password
exit()
except NoSuchElementException:
print('\nUsername/Password seems to be incorrect, please re-check\nand Re-Run the program.')
del username, password
exit()
try:
WebDriverWait(driver, 5).until(lambda webpage: "https://stackoverflow.com/" in webpage.current_url)
print('\nLogin Successful!\n')
except TimeoutException:
print('\nUsername/Password seems to be incorrect, please re-check\nand Re-Run the program.')
exit()
以上代码,带有2个参数-gmailID和密码。如果密码或用户名错误,则会通知您。
为什么要使用stackauth ?
-> Stackauth使用OAuth 2.0授权来访问Google API(此处,Google帐户登录需要Google API起作用),以安全地将用户登录到他/她的Google帐户。
Click here了解有关OAuth的更多信息。
答案 7 :(得分:1)
我尝试了此页面上的所有解决方案,但没有一个对我有用,但是我通过从我想要访问的帐户加载 chrome 用户数据来使其工作。只需:
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/{userName}/AppData/Local/Google/Chrome/User Data/Profile {#}/")
driver = webdriver.Chrome("C:/bin/chromedriver.exe", chrome_options=options)
因此,如果您有一个特定的 Google 帐户要访问,请使用它创建一个 chrome 配置文件,然后在使用 selenium 时加载 chrome 配置文件,如上所示。
上述文件路径中的配置文件 {#} 会有所不同,因此我建议在用户数据文件夹内检查您要使用的配置文件。例如,如果您目前只有 1 个 chrome 帐户,则用户数据中将没有配置文件目录(采用“默认”目录),但如果您创建第二个 chrome 帐户,则用户数据中将有一个“配置文件 1”目录。< /p>
请注意,您应该创建一个新的 google chrome 配置文件以与 selenium 一起使用,因为尝试使用已在使用中的 chrome 配置文件(在另一个 chrome 窗口中打开)会导致错误。
答案 8 :(得分:1)
我上周使用以下步骤解决了这个问题:
前两步不在您的项目代码中。
cd C:\Program Files\Google\Chrome\Application
chrome.exe --remote-debuggin-port=9222 --user-data-dir="C:\localhost"
您可以使用任何免费端口,但我遵循了这篇文章: https://chromedevtools.github.io/devtools-protocol/
浏览器窗口打开。 使用打开的窗口手动登录到 Google / Facebook / 等。 关闭浏览器。
在您的项目中:
/**
* This method is added due to Google security policies changed.
* Now it's impossible to login in Google account via Selenium at first time.
* We use a user data directory for Chrome where we previously logged in.
*/
private WebDriver setWebDriver() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir=" + System.getProperty("user.dir") + "/src/main/resources/localhost");
options.addArguments("--remote-debugging-port=9222");
return new ChromeDriver(options);
}
PS:如果您有其他解决方案而没有将chrome用户目录复制到项目中,请分享)
答案 9 :(得分:0)
您的帐户将自动打开。
async fn delay() {
for _ in 0..6 {
tokio::time::delay_for(std::time::Duration::from_millis(500)).await;
println!("Ping!");
}
}
async fn runner() {
let delayer = delay();
if let Err(_) = tokio::time::timeout(std::time::Duration::from_secs(2), delayer).await {
println!("Taking more than two seconds");
delayer.await;
}
}