|
You last visited: Today at 21:21
Advertisement
C# travian bot / webBrowser button click help
Discussion on C# travian bot / webBrowser button click help within the .NET Languages forum part of the Coders Den category.
08/05/2014, 19:24
|
#1
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
C# travian bot / webBrowser button click help
hello anyone worked on a travian bot or something? I cant figure out how to click on a button when I dont know button id or name
already tried searching by class but either I am noob or it doesnt work, tried putting Label in that location and get element by location and click but doesnt work either
can anyone help me?
|
|
|
08/05/2014, 21:26
|
#2
|
elite*gold: 155
Join Date: Aug 2009
Posts: 628
Received Thanks: 153
|
You could try to use HtmlAgilityPack for parsing the websites.
You can get HtmlAgilityPack via NuGet in Visual Studio.
My favorite approach to parse websites is to use HtmlAgilityPack and XPath to get any elements.
For getting the XPaths I use Firebug with Firefox.
You can get several examples on how to use Firebug and how XPaths work by searching on your favorite search engine.
Edit: Wrong section. #moverequest
|
|
|
08/05/2014, 23:13
|
#3
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
I got it to work, == for className is broke I had to use .Equals
thanks for reply still, do you think for a browser bot are HTTP requests better than web browser control? i would still implement browser for manual check but I heard requests are better but couldnt get POST requests for building with any tool
|
|
|
08/05/2014, 23:41
|
#4
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
|
C/C++ -> .NET Languages
#moved
|
|
|
08/06/2014, 08:51
|
#5
|
elite*gold: 155
Join Date: Aug 2009
Posts: 628
Received Thanks: 153
|
Quote:
Originally Posted by Buckyx
I got it to work, == for className is broke I had to use .Equals
thanks for reply still, do you think for a browser bot are HTTP requests better than web browser control? i would still implement browser for manual check but I heard requests are better but couldnt get POST requests for building with any tool
|
It depends on your needs.
If you want to see the websites then you would have to use a WebBrowser control.
If you have a custom GUI or just want to automate things and you don't need to see the websites then you are better off with HttpWebRequests.
There are plenty of examples out there on how to use HttpWebRequests for GET or POST requests. Just search for it on any search engine.
|
|
|
08/07/2014, 11:10
|
#6
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
yeah I am playing with http requests I can make my bot log in and train some troops, only thing I have problem with is I need to use hidden keys inside HTML tags and I dont know how to get them
I know but its very hard, I need to make webBrowser document from recieved HTML Text then searched what I need and then make request, searching just the text without html elements I dont know
|
|
|
08/07/2014, 22:07
|
#7
|
elite*gold: 1
Join Date: Aug 2013
Posts: 1,898
Received Thanks: 1,346
|
Quote:
Originally Posted by Buckyx
yeah I am playing with http requests I can make my bot log in and train some troops, only thing I have problem with is I need to use hidden keys inside HTML tags and I dont know how to get them
I know but its very hard, I need to make webBrowser document from recieved HTML Text then searched what I need and then make request, searching just the text without html elements I dont know
|
If I understand you correctly you want to make something like this below.
Not the fastest, but it works:
Code:
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
..
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URLHERE");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string response_text = sr.ReadToEnd();
Regex r = new Regex("<YOURHTMLTAG>.*?\"</YOURHTMLTAG>");
MatchCollection ms = r.Matches(response_text);
foreach (Match m in ms)
{
Regex extract_vars_r = new Regex(">".*?\"<");
Match extract_vars_m = extract_vars_r.Match(m.Value);
string dirtyString = extract_vars_m.Value;
string clearPhase1 = dirtyString.Replace(">", "");
string clearPhase2 = clearPhase1.Replace("<", "");
this.TextBox.Text += clearPhase2 + Environment.Newline;
}
|
|
|
08/07/2014, 22:21
|
#8
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
thanks all for reply, I found a way to do that using Html Agility Pack
Code:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(l_Response);
doc.DocumentNode.SelectSingleNode("...") - depends on what I need
I can basically do anything I think of, just need to set up timers and some conditions so it can be automated because I now use buttons for everythings just to check if it works
other thing I have problem with: I recieve reponse string and its somehow f-ed up so in webBrowser it seems very weird even when I decode HTML tags .. need to say I started working with C# few days ago for first time and havent made any code for few months
|
|
|
08/08/2014, 19:27
|
#9
|
elite*gold: 155
Join Date: Aug 2009
Posts: 628
Received Thanks: 153
|
Quote:
Originally Posted by Buckyx
thanks all for reply, I found a way to do that using Html Agility Pack
Code:
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(l_Response);
doc.DocumentNode.SelectSingleNode("...") - depends on what I need
I can basically do anything I think of, just need to set up timers and some conditions so it can be automated because I now use buttons for everythings just to check if it works
other thing I have problem with: I recieve reponse string and its somehow f-ed up so in webBrowser it seems very weird even when I decode HTML tags .. need to say I started working with C# few days ago for first time and havent made any code for few months 
|
I don't know what kind of f*cked up you mean, but the first thing I would check is if your response is compressed.
You can check this by checking if the response contains a "Content-Encoding" header that is set to some kind of compression method.
The most common compression method I guess is Gzip (at least I had never a different compression method).
Luckily the HttpWebRequest class can automatically decompress your content if you set the  properly.
You should examine if your target website compresses its responses (you can use Fiddler or Live Http Headers for this).
If it uses compression you can get the used algorithm from the recorded requests and responses.
Then you just set the AutomaticDecompression property:
Code:
request.AutomaticDecompression = DecompressionMethods.Gzip; // If Gzip is used.
request.AutomaticDecompression = DecompressionMethods.Deflate; // If Deflate is used.
request.AutomaticDecompression = DecompressionMethods.Gzip | Decompressionmethods.Deflate; // If both could be used.
If it is not a compression related issue then please tell us a bit more about your problem and/or post some of the weird content you got.
It also might be helpful if you could post your code where you read the response content out of your response object.
|
|
|
08/09/2014, 11:52
|
#10
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
well It doesnt show images and formatting is strange, even after decoding
but its not real issue, just was curious how webpages look likes so I can edit my requests if needed
.. is it possible to send more requests at one time? I dont want to use more web clients because I need to login with every separately
eg I need to do 900 requests, doing one by one takes some time
|
|
|
08/09/2014, 18:46
|
#11
|
elite*gold: 155
Join Date: Aug 2009
Posts: 628
Received Thanks: 153
|
Quote:
Originally Posted by Buckyx
well It doesnt show images and formatting is strange, even after decoding
but its not real issue, just was curious how webpages look likes so I can edit my requests if needed
.. is it possible to send more requests at one time? I dont want to use more web clients because I need to login with every separately
eg I need to do 900 requests, doing one by one takes some time
|
If you don't want to run them one by one you have to use Threads to run multiple requests concurrently.
I would just be careful with throttling. Many websites only allow a certain amount of requests in a given timeframe so you have to test if there is a limit.
|
|
|
08/10/2014, 14:43
|
#12
|
elite*gold: 0
Join Date: Jun 2009
Posts: 177
Received Thanks: 2
|
that wont help, server will ban my account after so may requests
I solved my bad formatting problem
I was copying request result to webbrowser.DocumentText
if I do .Navigate with "Content-Type: application/x-www-form-urlencoded" then it works like it should
but i dont want to navigate everytime, just want to copy my results from webclient to webbrowser, is this possible?
|
|
|
 |
Similar Threads
|
[VB.NET]Webbrowser Control Button ohne ID anklicken
11/13/2013 - .NET Languages - 5 Replies
Hey
Da ich keine lust mehr auf webrequest habe, hab ich versucht einen Bot mit Webbrowser Control zu coden. Nun weiß ich aber nicht, wie man einen Button anklickt, der keine ID besitzt.
Button:
<input type="submit" name="login_button" value="Login" tabindex="3" class="login">
Auf Google finde ich nur Müll der nicht funktioniert, egal wieviel ich damit experimentiere.
|
Button ohne Id im Webbrowser anklicken
09/23/2013 - .NET Languages - 10 Replies
Hallo, ich möchte gerne auf einer Website einen Button anklicken, eigentlich: Webbrowser1.Document.GetElementbyID(""). InvokeMember("click") aber Leider hat dieser Button keine Id, wie kann ich mein Problem anders lösen?
Achso und: ich möchte kein GetFromPoint benutzen, da der Button an verschiedenen stellen sein kann ....
|
[VB10] Button Click WebBrowser Problem
12/25/2012 - .NET Languages - 6 Replies
hi guys,
i have a problem, i want to click on a button.
this is the html code:
i thought that would be the solution:
WebBrowser1.Document.GetElementById("gStarte r").InvokeMember("Click")
i also tested to write the title/href/onclick instead of the "gStarter" but nothing works.
sorry, i am at the beginning of coding and i think i started a too huge project...
|
Webbrowser span click
12/05/2011 - .NET Languages - 2 Replies
Hallo erstmal,
nach stundenlangen googlen habe ich nichts gefunden was mir weiterhelfen könnte.
Ich möchte nähmlich einfach ein Programm schreiben das ein click im webBrowser auf ein bild ausführt.
Was erstmal einfach klingt aber nicht einfach ist xD.
Ich habe es schon mit
webBrowser1.Document.GetElementById("vote_li nk_1").InvokeMember("click");
versucht aber das geht leider nicht.
Hier ist mal der quellcode der Seite
<span id="vote_link_1" class="votelink">
|
Webbrowser vor-zurück button?
07/24/2011 - AutoIt - 2 Replies
Wollte mal fragen ob man bei einem selbstgemachtem Webbrowser einen Vor- und Zurückbutton machen kann und welche Funcktion <--- Parameter man braucht. Danke schonma
|
All times are GMT +1. The time now is 21:23.
|
|