9 Replies - 733 Views - Last Post: 10 April 2013 - 05:43 PM Rate Topic: -----

#1 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 133
  • Joined: 30-January 13

can someone please help me retrive source code from url

Posted 10 April 2013 - 05:02 PM

I am trying to figure out how to make a form where the user types a url in a text box then they hit a button and the source code of that page will show up in another text box. It is being used for a text editor such as text pad. I know how to make it where they can hit a button and get the source code from the site I specify such as
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myRequest As WebRequest
        myRequest = WebRequest.Create("http://www.yahoo.com")
        Dim theResponse As WebResponse = myRequest.GetResponse()
        Dim responseStream As Stream = theResponse.GetResponseStream()
        Dim reader As New StreamReader(responseStream)
        Dim sb As New StringBuilder
        Do
            sb.Append(reader.ReadLine)
            sb.Append(vbCrLf)

        Loop While Not reader.ReadLine Is Nothing
        TextBox1.Text = sb.ToString()
    End Sub
End Class

However I want it where they can pick any site through a text box by typing the url and hitting submit any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: can someone please help me retrive source code from url

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,255
  • Joined: 12-June 08

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:07 PM

So... a textbox's "text" property returns the string from the textbox, right? Why not use that in line 3 and not the hard coded address?
Was This Post Helpful? 0
  • +
  • -

#3 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 133
  • Joined: 30-January 13

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:08 PM

View Postmodi123_1, on 10 April 2013 - 07:07 PM, said:

So... a textbox's "text" property returns the string from the textbox, right? Why not use that in line 3 and not the hard coded address?

I was actually trying to do something like that but I could not seem to write it correct. Thank you for the fast reply.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,255
  • Joined: 12-June 08

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:11 PM

Well.. how are you trying to write it? I mean it's a pretty basic swap.
Was This Post Helpful? 0
  • +
  • -

#5 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 133
  • Joined: 30-January 13

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:16 PM

well I tryed several differant ways but I am pretty new to vb and just could not figure it out I was trying things like this
        myRequest = WebRequest.Create.textbox2.text
        

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,255
  • Joined: 12-June 08

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:18 PM

WebRequest.Create("http://www.yahoo.com")

If the method create takes in a string why would you be trying to use the dot-operator to find a method or property called 'textbox2'? Why not just keep the method call (we know it is a method call because it has the ( and ) ), and just use the textbox's method?

WebRequest.Create(textbox2.text)

Was This Post Helpful? 1
  • +
  • -

#7 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 133
  • Joined: 30-January 13

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:23 PM

View Postmodi123_1, on 10 April 2013 - 07:18 PM, said:

WebRequest.Create("http://www.yahoo.com")

If the method create takes in a string why would you be trying to use the dot-operator to find a method or property called 'textbox2'? Why not just keep the method call (we know it is a method call because it has the ( and ) ), and just use the textbox's method?

WebRequest.Create(textbox2.text)

Thank you so much I tryed several ways and it was driving me crazy I even tryed like this
WebRequest.Create("textbox2.text")
once earlyer but I should have realized it was the "" that was messing me up lol. Thanks so much for the help.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,255
  • Joined: 12-June 08

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:25 PM

Do you know *WHY* the quotes were messing you up? Anything in a pair of quotes is automatically treated as a string and _NOT_ an object with a property call.
Was This Post Helpful? 0
  • +
  • -

#9 ak4744710  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 133
  • Joined: 30-January 13

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:27 PM

No to be honest I did not know that but glad I do now. It seems like it can be confusing but the more attention I pay Im noticing it gets pretty basic once you get practice and learn it.
Was This Post Helpful? 0
  • +
  • -

#10 IronRazer  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 371
  • View blog
  • Posts: 1,083
  • Joined: 01-February 13

Re: can someone please help me retrive source code from url

Posted 10 April 2013 - 05:43 PM

Hi,
You can also use (DownloadString) to get the source of the page. This is a little code that lar3ry showed me that may be a little smaller and less complicated. :bigsmile:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using wb As New System.Net.WebClient
            Dim s As String = wb.DownloadString(TextBox2.Text)
            Dim txt() As String = s.Split(CChar(vbLf))
            For Each line In txt
                TextBox1.Text &= line & vbNewLine
            Next
        End Using
    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1