Results 1 to 14 of 14

Thread: Read and split strings from a text file

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Read and split strings from a text file

    Hello everyone
    i am making an account follower so i have made a program creates accounts and writes the login details in a textfile in this format loginidass so i need help in reading the text file which could contain 200-300 different account details . Also how can i send the post form request with each id and pass in textfile . I am currently using Http as HttpClass .

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,762

    Re: Read and split strings from a text file

    So you need to extract the data from the text file to a list or a datatable? I have a function in the codebank here that converts a delimited text file to a datatable and vise-versa. From there, if you want to enter in the value of each row into an HtmlElement, you will need to first get the element using the .GetElementId method or some other GetElement method. Once you have the element, you set the value attribute using .SetAttribute method. Here is an example of how to use the SetAttribute method with an HtmlElement where it's Id is txtID:
    Code:
    Dim txt_input As HtmlElement = WebBrowser1.Document.GetElementId("txtID")
    
    txt_input.SetAttribute("value", "your id value here")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    Quote Originally Posted by dday9 View Post
    So you need to extract the data from the text file to a list or a datatable? I have a function in the codebank here that converts a delimited text file to a datatable and vise-versa. From there, if you want to enter in the value of each row into an HtmlElement, you will need to first get the element using the .GetElementId method or some other GetElement method. Once you have the element, you set the value attribute using .SetAttribute method. Here is an example of how to use the SetAttribute method with an HtmlElement where it's Id is txtID:
    Code:
    Dim txt_input As HtmlElement = WebBrowser1.Document.GetElementId("txtID")
    
    txt_input.SetAttribute("value", "your id value here")
    Public Class Form2


    Dim Http As New HttpClass("https://link.com")
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If (user.Text = "" Or pass.Text.ToString() = "" Or TextBox1.Text = "").ToString() Then

    MessageBox.Show("Fields can not be blank!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)


    Else


    id = user.Text
    pas = pass.Text.ToString()


    post = "form_sent=1&referer=&next=&username=" + id + "&password=" + pas + "&passwordfake=Password"
    Me.ToolStripStatusLabel1.Text = label + "Signing In ...."
    Http.Request("GET", "http://link.com/login", Nothing)
    Http.Request("POST", "http://link.com//login", post)
    Me.ToolStripStatusLabel1.Text = label + "Logged In ...."
    Me.ToolStripStatusLabel1.ForeColor = Color.IndianRed
    source = Http.Request("GET", http://link.com/" + TextBox1.Text, Nothing)
    Me.ToolStripStatusLabel1.Text = label + "Following -> " + TextBox1.Text
    Try
    Dim r As New System.Text.RegularExpressions.Regex("<input type=""hidden"" name=""example"" value="".*"" />")
    Dim rr As New System.Text.RegularExpressions.Regex("<input type=""hidden"" name=""example1"" value="".*"" />")
    Dim matches As MatchCollection = r.Matches(source)
    Dim matches1 As MatchCollection = rr.Matches(source)
    For Each f As Match In matches
    re = f.Value.Split("""").GetValue(5)


    For Each ff As Match In matches1


    re1 = ff.Value.Split("""").GetValue(5)
    Next


    Next
    Catch ex As Exception
    Console.WriteLine(ex)
    End Try
    Dim fol = "friend=" + re + "&validate=" + re1
    unfollow = fol.ToString()
    Http.Request("POST", "http://link.com/", fol)
    MsgBox("Done!")
    Me.ToolStripStatusLabel1.Text = label + "DONE !"
    Console.WriteLine(fol.ToString())




    End If
    End Sub
    I am not actually using webbrowser for it all i want to do is for each value1:value2 in the textfile i want to send the post request i have quoted above

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Read and split strings from a text file

    Quote Originally Posted by TeraBaap View Post
    I am not actually using webbrowser for it all i want to do is for each value1:value2 in the textfile i want to send the post request i have quoted above
    You say you are using the HttpWebRequest class. It's by know means for beginners. If you can create One request why cant you simulate 200? Did you ever consider to post your code?

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Read and split strings from a text file

    &passwordfake=Password
    Uh, huh?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    i did post the code although i couldnt post all of it cuz there is too much of it .But Suppose if there is a text file where the user credentials are stored in value1:value2 in each line how can retrieve the value1 and value2 and parse the values to id and pas variable .

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    its just how the form data is lol .

  8. #8
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: Read and split strings from a text file

    Hi

    But Suppose if there is a text file where the user credentials are stored in value1:value2 in each line how can retrieve the value1 and value2 and parse the values to id and pas variable .
    maybe this is something your after
    (Psuedo)

    read the data into a list of string

    for each item in list
    dim data as list(of string)
    'use the split function here,it will seperate data in delimited format and put it into a list'

    dim name as string = data(0)
    dim password as string = Data(1)

    Next
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    Quote Originally Posted by GBeats View Post
    Hi



    maybe this is something your after
    (Psuedo)

    read the data into a list of string

    for each item in list
    dim data as list(of string)
    'use the split function here,it will seperate data in delimited format and put it into a list'

    dim name as string = data(0)
    dim password as string = Data(1)

    Next
    hmm could you give me an example ?
    and it should be " for each item as String in list " instead of for each item in list " ?

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    Let me make this a bit more clear the text file from which i want to parse data has content like this
    PHP Code:
    Value1:value2
    Value3
    :Value4
    Value5
    :Value6 
    *note : all these values represent different user credentials

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Read and split strings from a text file

    and it should be " for each item as String in list " instead of for each item in list " ?
    You were told that this was Pseudo code (albeit with mispelling) so actual syntax is not at issue here.

    could you give me an example ?
    Seriously? You have a code including Regex and Http Requests and you need an example of a For Each loop? That doesn't look suspicious at all!

    Get thee to VB.Net kindergarten ... here and here.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  12. #12

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    35

    Re: Read and split strings from a text file

    Quote Originally Posted by dunfiddlin View Post
    You were told that this was Pseudo code (albeit with mispelling) so actual syntax is not at issue here.



    Seriously? You have a code including Regex and Http Requests and you need an example of a For Each loop? That doesn't look suspicious at all!

    Get thee to VB.Net kindergarten ... here and here.
    First of all english isnt my primary language so i couldn't undertand what pseudo code means secondly just because my program includes Regex and Httpwebrequests (i did had help in making a cookie container for storing session cookies) just doesnt mean i c+p if thats what you are implying right there sir . I do know what for each loop is i just dont know about List as ive never used it .

  13. #13
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: Read and split strings from a text file

    its best to do a for each loop like

    for each item as <whatever> in <whatever>

    or

    Dim Item as <whatever>

    for each item in <whatever>

    ..
    ..

    and really you should do the simple stuff yourself, at least show an effort to try, you will be helped if you try it for yourself, seriously.

    regex is super simple after you try it out yourself, just goto MSDN site and find an example......

    but regex will take time to get right as getting the 'Check' Part right sometimes gets tricky.

    as for split

    i think its string.split(string, delimiter) or something similar, look it up its super simple to use
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  14. #14
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Read and split strings from a text file

    Ok we will give you the benefit of the doubt and you did write this. Your regex is extremely greedy. What data does this field contain.

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private ReadOnly m_someFile() As String = IO.File.ReadAllLines("path")
    4.  
    5.     Private Sub SomeMethod()
    6.         For Each item In Me.m_someFile
    7.             Dim parts() As String = item.Split(":"c)
    8.             Threading.ThreadPool.QueueUserWorkItem(Sub() SomeRequest(parts(0), parts(1)))
    9.         Next
    10.     End Sub
    11.  
    12.     Private Sub SomeRequest(ByVal userName As String,
    13.                             ByVal password As String)
    14.         ' Do what ever
    15.     End Sub
    16.  
    17. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width