Visual Basic Coding Question

phpfail

Regular Member
Joined
Aug 21, 2011
Messages
236
Reaction score
107
** RESOLVED ** thanks for the help.

Okay so I've been coding a bot and I've ran into a problem, it's the only thing holding back the completion of my bot. The bot is trying to click a button on a page, but theres more then one button and theres no unique identifier, so all the buttons are the same code, so the bot ends up clicking all the buttons on the page. The only unique identifier is the div id which surrounds each button.

Example
Code:
<div id="93edufjai" name="whatever">
some random code /text

<button type="button">

</div>

So my question is this, how would I get the bot to click the button within the specified div with the correct ID, here is my code I'm using but it clicks all buttons not the button within the div.

Code:
      For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
            If element.GetAttribute("id") = "93edufjai" Then
        For Each ele As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
            If ele.GetAttribute("type") = "submit" Then
                ele.InvokeMember("click")
            End If
        Next
End If
Next


If anyone could help me I'd greatly appreciate it and maybe do something for you in return, I can code php and design very clean and professional websites. Or I can send you some money on paypal when I get paid next week. Thanks in advance for any help
 
Last edited:
I was going to in a later version, just need to get it functioning first, i was going to ditch the web browser in a later version of the program, do you know how to fix my problem?
 
var butt = webBrowser1.Document.GetElementsByTagName("button").Cast<HtmlElement>().FirstOrDefault(bt => ((bt.Parent.TagName == "div") && (bt.Parent.Id == "93edufjai"))); if (butt != null) { butt.InvokeMember("click"); }
 
nothing wrong in using webbrowser ... those who don't know how to use it correctly complains..
 
var butt = webBrowser1.Document.GetElementsByTagName("button").Cast<HtmlElement>().FirstOrDefault(bt => ((bt.Parent.TagName == "div") && (bt.Parent.Id == "93edufjai"))); if (butt != null) { butt.InvokeMember("click"); }

Is this for visual basic? I get a bunch of errors, I know its written in javascript, but I've never used visual basic in javascript, I'll do some googling and see if/how to use js in visual basic. Thank you so much tho!

Also, the div id is not named just id,its data-id, so im unsure of how to change the parent.id to get the data-id
 
Last edited:
Dim butt = webBrowser1.Document.GetElementsByTagName("button").Cast(Of HtmlElement)().FirstOrDefault(Function(bt) ((bt.Parent.TagName = "div") AndAlso (bt.Parent.Id = "93edufjai")))If butt IsNot Nothing Then butt.InvokeMember("click")End If
 
Dim butt = webBrowser1.Document.GetElementsByTagName("button").Cast(Of HtmlElement)().FirstOrDefault(Function(bt) ((bt.Parent.TagName = "div") AndAlso (bt.Parent.Id = "93edufjai")))If butt IsNot Nothing Then butt.InvokeMember("click")End If

I'm getting a "expecting end of statement" error right at "If butt"
 
sorry for all of the hassle, but I really appriciate it. Also the name of the div id is dat-id now just id, so i dont think parent id would work
 
Are you trying to make a youtube comment rater?

It is a comment upvoter but not for youtube, but I looked at youtube's coding and it is very similar, but instead of div youtube uses li
 
Back
Top