SRL Archive - C#/Visual Basic Help and Tutorials

GetPage in Visual Basic 2008?


Sabzi

2009-11-28 09:22:25

So is there a function like that in vb?
If no then how can I place a webpage's source code into a string?

Also as I am learning the language it would be cool to have someone on msn who can and would like to help. Be ready that I may ask totally dumb questions tho.

Oh, and I don't know if it's important or not but now I am just writing console applications and my teacher doesn't want me to use object oriented features first.

Thanks in advance!

fronty

2009-11-28 12:01:05

I would use System.Net.WebClient.

// in C#
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.StreamReader reader = wc.OpenRead("http://www.google.fi");
System.Console.WriteLine(reader.ReadToEnd());

rogeruk

2009-11-28 12:39:19

Private Sub Command1_Click()
Open App.Path & "\test.html" For Input As #1
Do While Not EOF(1) ' Loop until end of file.
Input #1, mystring ' Read data into two variables.
Text1.Text = Text1.Text & mystring & vbCrLf
Loop
Close #1
End Sub

If you want to read HTML without using the browser control then use this..

Dim objLink As HTMLLinkElement
Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDocument As MSHTML.HTMLDocument


' This function is only available with Internet Explorer 5

Set objDocument = objMSHTML.createDocumentFromUrl(txtURL.Text, _
vbNullString)

' Tricky, to make the function wait for the document to
' complete, usually the transfer is asynchronous. Note
' that this string might be different if you have another
' language than English for Internet Explorer on the
' machine where the code is executed.

While objDocument.readyState <> "complete"
DoEvents
Wend

' Source Code

Debug.Print = objDocument.documentElement.outerHTML

' Title

Debug.Print "Title : " & objDocument.Title

' Link Collection

For Each objLink In objDocument.links
lstLinks.AddItem objLink
Debug.Print "Link: " & objLink
Next

http://www.codeguru.com/vb/vb_internet/html/article.php/c4815/

Sabzi

2009-11-28 12:46:12

Actually it's php.
For example: http://www.heroesofnewerth.com/heroview.php?hid=15
Sorry that I forgot to mention this.
Currently I am trying what fronty said and I already learned a few new thing. I will report back how it goes.

rogeruk

2009-11-28 12:50:26

Doesnt matter you wont be able to read PHP.

Everything on that page is in HTML.

If you tell us excatly what your trying to do then that may help instead of us posting help which is irrelevant.

Sabzi

2009-11-28 13:03:35

I just wanted to get the source of the webpage to a string. Just like GetPage works in scar.
But basicly I want this:
program New;

procedure FillUp;

var
S, HeroName, StatName, Stat: string;
SA, SAI: TStringArray;
H, i, o, p: Integer;

begin
SAI := ['<li class="cat" style="width: 170px;">Movement Speed</li>', +
'<li class="cat" style="width: 170px;">Str per Level</li>', +
'<li class="cat" style="width: 170px;">Agi per Level</li>', +
'<li class="cat" style="width: 170px;">Int per Level</li>', +
'<li class="cat" style="width: 170px;">Armor</li>', +
'<li class="cat" style="width: 170px;">Dmg. Reduction</li>', +
'<li class="cat" style="width: 170px;">Magic Armor</li>', +
'<li class="cat" style="width: 170px;">Magic Dmg. Reduction</li>'];
for p := 0 to 116 do
begin
S := GetPage('http://www.heroesofnewerth.com/heroview.php?hid=' + IntToStr(p) + '');
HeroName := Between('Hero Name</b></span><br>', '<br>', S);
if HeroName = '' then Continue;
WriteLn(HeroName + ':' + #13);
SA := Explode(#10, S);
H := High(SA);
for o := 0 to 7 do
begin
for i := 0 to H do
begin
if Pos(SAI[o], SA[i]) > 0 then
begin
StatName := Between('>', '<', SAI[O]);
Stat := Between('>', '<', SA[i + 2]);
WriteLn(StatName + ': ' + Stat);
WriteINI(HeroName, StatName, Stat, ScriptPath + 'HeroDatabase.ini');
Break;
end;
end;
end;
WriteLn(#13);
end;
end;


var
f: Integer;

begin
FillUp;
end.
in VB.

But I don't want you just to give me a full working program because I won't learn from that too much.

EDIT: I got it now with fronty's method. Although it's not in a string, yet.

rogeruk

2009-11-28 13:13:24

Fair comment.

http://www.vbforums.com/showthread.php?t=423374
http://www.vbforums.com/showpost.php?p=2589456&postcount=4

They should help you.

Sabzi

2009-11-28 13:25:25

From: rogeruk
Fair comment.

http://www.vbforums.com/showthread.php?t=423374
http://www.vbforums.com/showpost.php?p=2589456&postcount=4

They should help you.


Oh! I was about to write Between but now I don't have to. Thank you! Can't rep you twice :p

rogeruk

2009-11-28 13:31:41

From: Sabzi
Oh! I was about to write Between but now I don't have to. Thank you! Can't rep you twice :p


No problemo.

Sabzi

2009-11-28 16:25:46

I don't want to start a new thread so I ask here.
Everything except the WriteINI line is okay(thx to you all).
I have found something about that in the "library" but it was so long mentioning registry and I don't know what that I felt like I don't want it.
Is there any easier way of doing that?

tl;dr:
WriteINI(HeroName, StatName, Stat, ScriptPath + 'HeroDatabase.ini');
^this in Visual Basic?(from the script a few post above)

Thx again!

rogeruk

2009-11-28 16:42:52

http://www.vbforums.com/showthread.php?t=349993

Check there.

Sabzi

2009-11-28 16:54:46

From: rogeruk
http://www.vbforums.com/showthread.php?t=349993

Check there.


<3!
I gotta check that forum next time before I ask :S

super_

2009-12-11 20:32:10

make use of the .NET BCL. System.Web :-)