Guten Morgen, alle
Ich bin gerade dabei ein kleines Programm zu schreiben, womit man auf einer Webseite erfolgreich einloggt und danach eine Bestätigung erhält, dass seine Anmeldung erfolgreich ist. Z.B. die Webseite: https://www.conquerclub.com/login
Ich habe folgendes probiert:
XAML-Datei
<StackPanel Orientation="Horizontal" Background="Black">
<TextBox x:Name="username" Width="200" Margin="2,2,10,2" Text="username"/>
<TextBox x:Name="password" Width="200" Margin="2,2,10,2" Text="password"/>
<Button Width="200" Content="Go!" Margin="2" Click="Button_Click" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="1" >
<WebBrowser x:Name="wb1" Height="500" />
<TextBlock x:Name="state" Text="Connection" ></TextBlock>
</StackPanel>
Code Behinde
...
public MainWindow()
{
InitializeComponent();
wb1.LoadCompleted += new LoadCompletedEventHandler(bws_LoadCompleted);
wb1.Navigated += new NavigatedEventHandler(bws_Navigated);
}
void bws_Navigated(object sender, NavigationEventArgs e)
{
HideScriptErrors(wb1, true);
}
void bws_LoadCompleted(object sender, NavigationEventArgs e)
{
switch (e.Uri.AbsolutePath)
{
case "/":
DoExample1();
break;
case "/login":
DoExample1();
break;
}
}
private void DoExample1()
{
TryFillInBing(username.Text, password.Text);
}
void TryFillInBing(string name, string passwd)
{
Thread.Sleep(500);
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
if (!LoginInput(0, "username", "password", name, passwd) && Tries < 6)
{
Tries++;
TryFillInBing(name, passwd);
}
else
{
IHTMLFormElement form = GetForm(0);
form.submit();
}
}));
}
private bool UpdateTextInput(int formId, string name, string text)
{
bool successful = false;
IHTMLFormElement form = GetForm(formId);
if (form != null)
{
var element = form.item(name: name);
if (element != null)
{
var textinput = element as HTMLInputElement;
textinput.value = text;
successful = true;
}
}
return successful;
}
private bool LoginInput(int formId, string name, string passwd, string text, string pw)
{
bool successful = false;
IHTMLFormElement form = GetForm(formId);
if (form != null)
{
var element = form.item(name);
var pass = form.item(passwd);
if (element != null && pass != null)
{
var textinput = element as HTMLInputElement;
textinput.value = text;
var passinput = pass as HTMLInputElement;
passinput.value = pw;
successful = true;
}
}
return successful;
}
...
...
...
private void Button_Click(object sender, RoutedEventArgs e)
{
string conquerclubLogin = "https://www.conquerclub.com";
string googleWeb = "http://www.google.de";
wb1.Navigate(conquerclubLogin);
}
Mein Problem ist dass die Seite nicht eingeloggt ist und ich keine Rückmeldung erhalten habe...hat jemand eine Idee, ob ich irgendwo falsch gemacht habe?
Vielen Dank!
VG, Carvin
Ich entnehme mal der Webseite "Bots & Human Play", dass Bots erlaubt sind.
Ansonsten hätte ich den Thread nun gelöscht.
Prinzipiell spricht man aber keine solchen Applikationen über die Oberfläche an, sondern über eine API.
Im Falle Deiner Webseite ist das http://www.conquerclub.com/api.php
Ich bezweifle, dass das, was Du da versuchst, a) von den Machern so den Sinn hat b) vermutlich auch nicht gewünscht ist und c) aufgrund der Menge und Aktualität des JavaScript so auch nicht mit reinen .NET Mitteln funktioniert.
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code