Results 1 to 7 of 7

Thread: [2008] Grab html source after logging in

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    [2008] Grab html source after logging in

    Using the code below I can get a page that doesn't require you to be logged in. But I need to be logged in to get the page I want..

    How would I modify it to be able to use cookies to log in and retrieve the page?

    What I eventually want to do is have a user and password input box on the form. Once the user clicks the button, it will grab the source and then manipulate it to how I want it.

    Code:
            Dim wc As New System.Net.WebClient
            Dim html As String = wc.DownloadString("https://www.webpage.com")
            RichTextBox1.Text = html

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Grab html source after logging in

    Use a WebBrowser control... It uses the same IE's cookies.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Grab html source after logging in

    Does setting the Credentials property of the WebClient work?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Grab html source after logging in

    I've tried using the code below but it gives me the same result as if I used no credentials. Could it be because the login is in a form and not a popup box?

    Code:
            Dim objWebClient As New WebClient()
            Dim Cred As New System.Net.NetworkCredential
            Cred.UserName = TextBox1.Text
            Cred.Password = TextBox2.Text
            objWebClient.Credentials = Cred
    
            Dim html As String = objWebClient.DownloadString("https://www.webpage.com")
            RichTextBox1.Text = html

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Grab html source after logging in

    Credentials will only work if it's a pop-up asking for your information (typically NTLM or whatever).

    There is no specific way to do what you want. Some sites might be able to use a cookie, others may use only sessions or other ways.

    What you should do is contact the webmaster and verify that you can do this. they will be able to tell you how. Also, if you plan on screen scraping once logged in, then don't. It's also a bad design idea and you should be contacting the webmaster to see if they have an API available.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Grab html source after logging in

    Using cookies I can do it fine with wget, but I'd like to remove that dependancy and just have to rely on vb.

    Code:
    Shell("C:\gnucore\bin\wget.exe --load-cookies c:\cookies.txt -O c:\mansion.html http://www.the4thcoming.net/players/House.asp?Function=SelectCharacter&PropPage=1&CharPage=1&UserID=" & a, AppWinStyle.Hide, True)
                Dim strLines As String() = IO.File.ReadAllLines("C:\mansion.html")

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Grab html source after logging in

    Bump..can anyone help me out here?

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