Opening multiple web pages simultaneously...
Hi!
I'm writing a program which gets the time and date from forums which only show "x hours ago" on the main thread list.
What I do is get a list of threads, open their print version and fetch the info.
I'm currently using a single webbrowser, because there's no control array anymore. This makes the proccess very slow.
Is there a way to open all the threads' print versions simultaneously?
(BTW, I'm using DOM functions like GetElementsByTag, so I'll need to get the page's "Document" object.)
Thanks!:wave:
Re: Opening multiple web pages simultaneously...
Can't you get the info with httpWebRequest directly?
You could create a class, that generates a new thread and a new webbrowser on it, and does what you want. Then just make a lot of those classes, but it won't go very fast either, I once did something very similar.
Re: Opening multiple web pages simultaneously...
Control arrays are irrelevant. A control array in VB6 was just multiple controls in an array. Why can't you add multiple controls and put them in an array in VB.NET? The fact that the design time support doesn't exist makes no difference. You can still add as many controls as you want and, if you need an array, you can create one in code.
That said, the very reason that design time support for control arrays doesn't exist in VB.NET is the fact that you can use a single method to handle events for multiple controls. That's all you need to do. Create a single DocumentCompleted event handler or whatever and have it handle the same event for multiple WebBrowser controls.
Re: Opening multiple web pages simultaneously...
I'll begin by saying I don't have much experience in this kind of programming.
@Dark Anima
Quote:
Can't you get the info with httpWebRequest directly?
You tell me. Is it possible to get a HtmlDocument object of a page using this method?
I'd like to know how this can be done.
@jmcilhinney
Quote:
if you need an array, you can create one in code.
I don't know how to do this. Can you please explain How?
In practical terms, I'd like to run a loop threw an array of webbrowsers, and each one will open a different forum thread, and later on I'll work on each webbrowser's HtmlDocument.
Re: Opening multiple web pages simultaneously...
Arrays are a fairly fundamental part of programming. I think that if you don't know how to create an array then you don't really have a grasp of the fundamentals, which you really should have before you start doing things like manipulating web pages in WebBrowser controls. If you learn to walk before trying to run you'd find that you wouldn't fall over so often. Pretty much any beginner tutorial will go through arrays fairly early on. Here are just two examples.
http://www.startvbdotnet.com/language/default.aspx
http://www.homeandlearn.co.uk/NET/nets6p1.html
Re: Opening multiple web pages simultaneously...
Quote:
Arrays are a fairly fundamental part of programming. I think that if you don't know how to create an array then you don't really have a grasp of the fundamentals, which you really should have before you start doing things like manipulating web pages in WebBrowser controls. If you learn to walk before trying to run you'd find that you wouldn't fall over so often. Pretty much any beginner tutorial will go through arrays fairly early on. Here are just two examples.
I don't know how to create an array of webbrowsers.
If it was as simple as creating an array of integers, I probably wouldn't come to this forum and ask about it, would I.
:confused:
Re: Opening multiple web pages simultaneously...
Quote:
Originally Posted by
bugger
I don't know how to create an array of webbrowsers.
If it was as simple as creating an array of integers, I probably wouldn't come to this forum and ask about it, would I.
:confused:
But it IS as simple as creating an array of Integers. An array is an array. What type its elements are makes no difference to how you create and populate the array.
vb.net Code:
Dim array1 As Integer() = {1, 2, 3}
Dim array2(2) As Integer
array2(0) = 1
array2(1) = 2
array2(2) = 3
vb.net Code:
Dim array1 As WebBrowser() = {Me.WebBrowser1, Me.WebBrowser2, Me.WebBrowser3}
Dim array2(2) As WebBrowser
array2(0) = Me.WebBrowser1
array2(1) = Me.WebBrowser2
array2(2) = Me.WebBrowser3
As you can see, it's exactly the same.
Re: Opening multiple web pages simultaneously...
1. Thanks for the example above. I didn't think it was THAT simple.
2. I was thinking of creating the webbrowser controls during runtime, because I can't really know how many threads there are in a forum. I've seen on others places that in order to do this I'd have to use the "New" command, but I'll have to read more about this, because I didn't quite understand how to use the new control's properties. (Eg. When I try this: msgbox(NewCtl.Document.Body.InnerText) I get an error).
Anyway, Thanks.
Re: Opening multiple web pages simultaneously...
If you're creating the controls at run time then an array is a perfect way to store them because if you don't know how many there are then you can't declare discrete variables, e.g.
vb.net Code:
Private Function CreateWebBrowsers(ByVal count As Integer) As WebBrowser()
Dim upperBound As Integer = count - 1
Dim browsers(upperBound) As WebBrowser
For index As Integer = 0 To upperBound
browsers(index) = New WebBrowser
Next
Return browsers
End Function
When you create the array it has the specified number of elements but each element is empty, just like an egg carton with no eggs. You have to create the WebBrowser objects and assign them to the elements of the array.