|
-
Feb 22nd, 2008, 04:14 PM
#1
Thread Starter
Member
[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
-
Feb 22nd, 2008, 06:36 PM
#2
Re: [2008] Grab html source after logging in
Use a WebBrowser control... It uses the same IE's cookies.
-
Feb 23rd, 2008, 07:14 AM
#3
Re: [2008] Grab html source after logging in
Does setting the Credentials property of the WebClient work?
-
Feb 23rd, 2008, 10:18 AM
#4
Thread Starter
Member
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
-
Feb 23rd, 2008, 02:40 PM
#5
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.
-
Feb 23rd, 2008, 04:15 PM
#6
Thread Starter
Member
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")
-
Feb 25th, 2008, 09:32 AM
#7
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|