gpt4 book ai didi

c# - 如何在 C#.net 中使用 awesomium 登录谷歌帐户?

转载 作者:行者123 更新时间:2023-11-30 15:27:14 25 4
gpt4 key购买 nike

我正在学习 Awesomium,下面是我尝试登录 https://accounts.google.com 的代码.我成功地能够在页面中设置登录名和密码字段值,但无法提交登录表单,点击也不起作用。谁能帮我登录一下?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Awesomium.Core;


namespace Awesom
{
class Program1
{
public static void Main(String[] args)
{
Console.WriteLine("Started....");

WebView wv = WebCore.CreateWebView(1024, 600);
wv.Source = new Uri("https://accounts.google.com");
wv.LoadingFrameComplete += (s, e) =>
{
if (!e.IsMainFrame)
return;

dynamic document = (JSObject) wv.ExecuteJavascriptWithResult("document");

using(document)
{
//Works
var tbox = document.getElementById("Email");
tbox.value = "XXXXXXXX@gmail.com";

//Works
var pbox = document.getElementById("Passwd");
pbox.value = "**********";

//Doesnt work
var lform = document.getElementById("gaia_loginform");
lform.submit();

//Doesnt work
var sbox = document.getElementById("signIn");
sbox.click();
}

BitmapSurface surface = (BitmapSurface)wv.Surface;
surface.SaveToPNG("result.png", true);

WebCore.Shutdown();
};

WebCore.Run();
}
}
}

结果图片:

enter image description here

最佳答案

它正在运行,您只是截图太早了。如果您使用 .click(),则需要考虑第二个框架导航。

public static void Main(String[] args)
{
Console.WriteLine("Started....");

WebView wv = WebCore.CreateWebView(1024, 600);

wv.Source = new Uri("https://accounts.google.com/");

FrameEventHandler handler = null;
handler = (s, e) =>
{
if (e.IsMainFrame)
{
// we have finished loading main page,
// let's unhook ourselves
wv.LoadingFrameComplete -= handler;

LoginAndTakeScreenShot(wv);
}
};

wv.LoadingFrameComplete += handler;

WebCore.Run();
}

private static void LoginAndTakeScreenShot(WebView wv)
{
dynamic document = (JSObject)wv.ExecuteJavascriptWithResult("document");

using (document)
{
//Works
var tbox = document.getElementById("Email");
tbox.value = "XXXXXXXX@gmail.com";

//Works
var pbox = document.getElementById("Passwd");
pbox.value = "**********";

FrameEventHandler handler = null;
handler = (sender, args) =>
{
if (args.IsMainFrame)
{
wv.LoadingFrameComplete -= handler;

BitmapSurface surface = (BitmapSurface)wv.Surface;
surface.SaveToPNG("result.png", true);

WebCore.Shutdown();
}
};

wv.LoadingFrameComplete += handler;

var sbox = document.getElementById("signIn");
sbox.click();
}
}

关于c# - 如何在 C#.net 中使用 awesomium 登录谷歌帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com