469,623 Members | 1,535 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Reading many pages of a web page

I'm using the following code to read in a web page as HTML:

' Download the web page using the chosen update method.
Dim sr As New
System.IO.StreamReader(wc.OpenRead("http://www.vbcity.com/forums/active.asp"
& _
Options.UpdateMethod))

Options.UpdateMethod contains "?action=1month&page=1"

I use the above code to find out how many pages in total exist in the query
to the web page using this code:

' Cature the current page & total page counts:
Dim regPageCount As New RegularExpressions.Regex("Page (\d{1,4}) of
(\d{1,4}):", _
Options:=RegularExpressions.RegexOptions.Singlelin e)

Dim ThisPage = regPageCount.Matches(strHtml).Item(0).Groups(1)
Dim TotalPages = regPageCount.Matches(strHtml).Item(0).Groups(2)

I then want to loop thru each page reading specific bits from each:

For Pages = ThisPage To TotalPages
For Each RegExMatch In regParagraph.Matches(strHtml)
'Trace.WriteLine(strNewLine)
Dim mLink As RegularExpressions.Match

RowCounter += 1

My problem is how do I requery each page in the loop. I tried:

Dim ThisPage = regPageCount.Matches(strHtml).Item(0).Groups(1)
Dim TotalPages = regPageCount.Matches(strHtml).Item(0).Groups(2)
Dim Pages As Integer

For Pages = ThisPage To TotalPages
' Download the web page using the chosen update method.
Dim sr As New
System.IO.StreamReader(wc.OpenRead("http://www.vbcity.com/forums/active.asp"
& _
Options.UpdateMethod &
"&Page=" & Pages))
For Each RegExMatch In regParagraph.Matches(strHtml)
'Trace.WriteLine(strNewLine)
Dim mLink As RegularExpressions.Match

but the "sr" in the 7th line is highlighted with the error "Variable 'sr'
hides a variable in an enclosing block." I suppose I can't redim it, so do I
have to use another variable name instead?
--
|
+-- Thief_
|
Nov 21 '05 #1
2 1058
Thief,

Did I show you already this sample on our website, in my opinion is it at
least much more consistent than what you are showing now.

http://www.windowsformsdatagridhelp....f-56dbb63fdf1c

If you want to read a complete page you can use however as well the
axwebbrowser, that returns more frames in one navigation session.

I hope this helps,

Cor
Nov 21 '05 #2
"Thief_" <th****@hotmail.com> schrieb:
' Download the web page using the chosen update method.
Dim sr As New
System.IO.StreamReader(wc.OpenRead("http://www.vbcity.com/forums/active.asp"
& _
Options.UpdateMethod))

Options.UpdateMethod contains "?action=1month&page=1"

I use the above code to find out how many pages in total exist in the
query
to the web page using this code:

' Cature the current page & total page counts:
Dim regPageCount As New RegularExpressions.Regex("Page (\d{1,4}) of
(\d{1,4}):", _
Options:=RegularExpressions.RegexOptions.Singlelin e)

Dim ThisPage = regPageCount.Matches(strHtml).Item(0).Groups(1)
Dim TotalPages = regPageCount.Matches(strHtml).Item(0).Groups(2)

I then want to loop thru each page reading specific bits from each:

For Pages = ThisPage To TotalPages
For Each RegExMatch In regParagraph.Matches(strHtml)
'Trace.WriteLine(strNewLine)
Dim mLink As RegularExpressions.Match

RowCounter += 1

My problem is how do I requery each page in the loop. I tried:

Dim ThisPage = regPageCount.Matches(strHtml).Item(0).Groups(1)
Dim TotalPages = regPageCount.Matches(strHtml).Item(0).Groups(2)
Dim Pages As Integer

For Pages = ThisPage To TotalPages
' Download the web page using the chosen update method.
Dim sr As New
System.IO.StreamReader(wc.OpenRead("http://www.vbcity.com/forums/active.asp"
& _
Options.UpdateMethod &
"&Page=" & Pages))
For Each RegExMatch In regParagraph.Matches(strHtml)
'Trace.WriteLine(strNewLine)
Dim mLink As RegularExpressions.Match

but the "sr" in the 7th line is highlighted with the error "Variable 'sr'
hides a variable in an enclosing block." I suppose I can't redim it, so do
I
have to use another variable name instead?


Either rename the variable or replace the line 'Dim sr As New
StreamReader(...)' with 'sr = New StreamReader(...)'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Piz | last post: by
2 posts views Thread by kinh | last post: by
29 posts views Thread by Jerim79 | last post: by
3 posts views Thread by Patrick Dugan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.