Visual Basic .NET Forums    

Go Back   Visual Basic .NET Forums > Components & Controls > Net / Sockets

VB.NET Forums Newsletter Signup:
Email address:


Net / Sockets Components for network and related use

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2008, 8:20 AM
Mog Mog is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Age: 23
Posts: 4
Reputation: 0
Mog is on a distinguished programming path ahead
Default Reading From Web Page

I'm using VB.NET 2003 if that makes any difference...

I have been searching around for how to do this for a while now and I just can't seem to get anything to work (well except for one part... which I will detail further down).

What I am trying to do is read data from a table on a web page where a login is required.

Before I can even get to that data I have to login to the website, which is where I run into my first problem... I can setup the request just fine and I've tried setting the credentials using System.Net.NetworkCredentials("username","password ") but it never logs me in properly and I only end up getting a read on the login page no successful/failed login at all.

As I've already said I got the read of the page down, just not the page I want... This part probably can be answered by the credentials part above, but do I give the request the page I want first and the login credentials works and brings me to the proper page or do I have to go to the login page then force the request to go to the page I want?

Once I have the page's html into a string variable how do i get the data out of the specific table? The table is always in the same spot, always has the same header information with changing information after that. I can deal with the data once I get it separated just don't know how to separate it easily.

In short any code samples for logging into a web site where networkcredentials doesn't work or an explanation of how to make networkcredentials work on any site would be great. Also, a code sample of how to read each column of each row of a html table. With those 2 code samples I can probably work it out myself.

Feel free to ask questions for more details or point me in the proper direction for where to look for this stuff. Please don't get mad and say "search could find this all for you" as I have no idea what to search for and I'm getting pretty tired/frustrated with not being able to find what I want.
Reply With Quote
  #2 (permalink)  
Old 12-02-2008, 11:13 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 8,138
Reputation: 876
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

It can be done both with a WebBrowser control (visible/hidden) that you automate, or with a at least two WebRequest, where you first go to login page and perform the login and most likely pick up the correct cookies, then go on to the target page. About WebRequest and cookies see this thread: HttpWebRequest and Cookies

The WebBrowser control makes it usually easy to navigate through the document object model tree to get data from tables and such, without it you can use basic string searching and regular expressions, or using Html parsing libraries as mentioned in this post: http://www.vbdotnetforums.com/84994-post4.html

... I just noticed you're on 2003, WebBrowser is not available for you, but the older ActiveX COM control is (AxWebBrowser I think), which is in cases like this often used along with the mentioned MSHTML COM library. Btw, you should really upgrade, even the free VB 2008 Express should be better for you than 2003.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
  #3 (permalink)  
Old 12-02-2008, 6:33 PM
Mog Mog is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Age: 23
Posts: 4
Reputation: 0
Mog is on a distinguished programming path ahead
Default

Well if it can all be done in one control easily with .NET 2008, then I will just upgrade to that.

I assume at some point the cookies in "CookieJar" get filled with the username and password?

Will need to look up this webbrowser control I'm quite interested now. Thanks.
Reply With Quote
  #4 (permalink)  
Old 12-02-2008, 7:39 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 8,138
Reputation: 876
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

The WebBrowser control (as of .Net 2.0) is a managed wrapper for the old AxWebBrower + MSHTML COM libraries, does the same and have same basic capabilities only wrapped to the much nicer .Net librarys strong type code style, instead of the "everything is Object or an interface and nothing seems connected" COM style where you can't do much without reading lots of cryptic old reference material. Like Internet Explorer this control handles cookies automatically when browsing web pages.

For the WebRequest approach the CookieContainer is usually used for login pages, when you login the page app set some special value there that it uses later to see that the request was previously authenticated, plain user/pass should never be found in a cookie.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
  #5 (permalink)  
Old 12-02-2008, 8:08 PM
Mog Mog is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Age: 23
Posts: 4
Reputation: 0
Mog is on a distinguished programming path ahead
Default

Does this webbrowser control work with console apps? Figured I would keep the program simple and make it a console app since its gonna be running automatically on a schedule. Guess I'll be digging through msdn and what not.
Reply With Quote
  #6 (permalink)  
Old 12-02-2008, 9:10 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 8,138
Reputation: 876
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Quote:
Does this webbrowser control work with console apps?
More awkward, but can be done. I'd rather run it with a minimized forms app that closes itself.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )
Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ


DR. WEIR: Download it to a non-networked, firewalled computer.
TECHNICIAN: Yes, ma'am.
Reply With Quote
  #7 (permalink)  
Old 12-02-2008, 9:14 PM
Mog Mog is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2008
Age: 23
Posts: 4
Reputation: 0
Mog is on a distinguished programming path ahead
Default

Mmk, was figuring I would do a self closing form if it could only be done with forms... Might do it that way anyways.

Gotta read up on webbrowser control and get VS 2008 before I ask more questions :P

EDIT: Ok, I think I've got all I need... its logging in, moving to the page I want, then pulling the data from the table... just gotta fire that data into a datatable/dataset and I will be golden from there.

Thanks for the help on this JohnH, it was much appreciated.

Last edited by Mog; 12-03-2008 at 8:33 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 4:23 AM.




Click to advertise here

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
For advertising opportunities click here.