Results 1 to 5 of 5

Thread: Fill the fields in dynamically created webbrowser

  1. #1

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    62

    Fill the fields in dynamically created webbrowser

    Hi, i created dynamically webbrowser in for loop and navigate to url, i want fill the username fields with MyBrowser_DocumentCompleted events but no success, i am adding AddHandler but again not succes, ho can i fill the fields in for loop.

    I created all elements in action without only tabcontrol, add tabcontrol in form and delete tabpages firstly.

    PHP Code:
    Public Class Form1

        Dim WithEvents MyBrowser 
    As New WebBrowser

        
    Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load

            Dim Sites
    () As String = {"Facebook""Linkedin"}
            
    Dim Url() As String = {"https://m.facebook.com/""https://www.linkedin.com/uas/login"}

            For 
    0 To Sites.Length 1
                Dim TabControl 
    As New TabControl
                Dim newTabPage 
    As New TabPage()
                
    Dim MyBrowser As WebBrowser = New WebBrowser

                newTabPage
    .Text Sites(i)
                
    TabControl1.TabPages.Add(newTabPage)

                
    AddHandler MyBrowser.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf MyBrowser_DocumentCompleted)
                
    newTabPage.Controls.Add(MyBrowser)
                
    MyBrowser.Navigate(Url(i))
                
    MyBrowser.Dock DockStyle.Fill
                MyBrowser
    .ScriptErrorsSuppressed True

            Next

        End Sub

        
    Private Sub MyBrowser_DocumentCompleted(ByVal sender As System.ObjectByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgsHandles MyBrowser.DocumentCompleted

            MyBrowser
    .Document.GetElementById("m_login_email").SetAttribute("value""mymail")
            
    MyBrowser.Document.GetElementById("username").SetAttribute("value""myusername")

        
    End Sub

    End 
    Class 
    Last edited by Enigmatic; May 1st, 2019 at 03:37 AM.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    62

    Re: Fill the fields in dynamically created webbrowser

    Any ideas?

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Fill the fields in dynamically created webbrowser

    What isn't working?

    For one thing, this is a bad idea. Automating interactions with web pages is ultimately doomed to frustration. Those who maintain web pages frequently change them, so what works today will fail tomorrow. This is done for a variety of reasons. In the case of the two sites you show in your code, they both have terms of service limiting what you can do automatically. Logging in is not explicitly prohibited, or this thread would be closed, since we do not support the writing of anything that violates the terms of service of other sites. However, since both of these sites forbid content scraping, then they probably make automated logins as difficult as they possibly can be. You may simply be writing to the wrong place, or in a way that it is getting rejected.

    Any site that WANTS you to be able to automate actions will provide an API for you to use. The advantage of an API is that you don't have to go through the painful steps that you are taking of loading a page, waiting for parts to finish loading, then trying to find fields, add data, submit data, and so on. Also, an API won't change very often, if at all, so you can count on an application that uses an API to keep working while you can count on a web scraping application to keep failing as changes to the page are made.

    So, what you are trying to do is not explicitly prohibited, but it is very likely that the sites have made it difficult, and possibly even impossible to do right. Use the API, if possible.
    My usual boring signature: Nothing

  4. #4
    Frenzied Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,168

    Re: Fill the fields in dynamically created webbrowser

    Quote Originally Posted by Shaggy Hiker View Post
    What isn't working?

    For one thing, this is a bad idea. Automating interactions with web pages is ultimately doomed to frustration. Those who maintain web pages frequently change them, so what works today will fail tomorrow. This is done for a variety of reasons. In the case of the two sites you show in your code, they both have terms of service limiting what you can do automatically. Logging in is not explicitly prohibited, or this thread would be closed, since we do not support the writing of anything that violates the terms of service of other sites. However, since both of these sites forbid content scraping, then they probably make automated logins as difficult as they possibly can be. You may simply be writing to the wrong place, or in a way that it is getting rejected.

    Any site that WANTS you to be able to automate actions will provide an API for you to use. The advantage of an API is that you don't have to go through the painful steps that you are taking of loading a page, waiting for parts to finish loading, then trying to find fields, add data, submit data, and so on. Also, an API won't change very often, if at all, so you can count on an application that uses an API to keep working while you can count on a web scraping application to keep failing as changes to the page are made.

    So, what you are trying to do is not explicitly prohibited, but it is very likely that the sites have made it difficult, and possibly even impossible to do right. Use the API, if possible.
    Just to add on, they do not prohibit auto-fill what they discourage is automatically logging in by means of automation, or non-user contact.

    I honestly discourage this as well, but if you NEED to login to a website automatically, or want to make your life easier, take advantage of stay login features that BOTH of these sites have. Unfortunately its hard to do in VB since the controls are disposed on exit.
    Disclaimer: When code is given for example - it is merely a example.




    Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    62

    Re: Fill the fields in dynamically created webbrowser

    I gave these sites as examples. I have subscribed commercial sites, I would like to store the addresses and passwords of these sites in the configuration file and facilitate my work. After logging in, I need to get my sales reports. I wouldn't have a job with my facebook. I'm sending the real image of the system I'm trying to do, see here. also don't look at every helper with exploitative eyes.

    Name:  vbforum.jpg
Views: 89
Size:  23.2 KB

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