0

I am opening a new tab in the browser and i want to save the page in html format.

My code is :

Page.ClientScript.RegisterStartupScript(Me.[GetType](), "OpenWindow", "window.open('https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=stack+overflow','_newtab');", True)

Here am opening a new window.Now i want to save the new web page in the html format. Please help me how to save the web page in new opened tab.

MDP
  • 17
  • 1
  • 7

1 Answers1

0

If you want to capture the response from a given URL server-side and save it to a file on the server, you can do something like this, using the WebRequest class:

Dim request As WebRequest = WebRequest.Create("http://www.example.com")

Using response As WebResponse = request.GetResponse()
  Using reader As New StreamReader(response.GetResponseStream())
    Dim html As String = reader.ReadToEnd()
    File.WriteAllText("test.html", html)
  End Using
End Using
ADyson
  • 57,178
  • 14
  • 51
  • 63
  • I am trying to save the webpage connected to the login page. If I use this code it downloads the webpage of login and showing session expired error. – MDP Jan 05 '17 at 11:29
  • that's a totally different matter then and wasn't what you asked - your example was just a random google search page. What type of authentication does the page use? (e.g. basic, windows/ntlm, or a html login form?) – ADyson Jan 05 '17 at 11:30
  • Sorry i forget to change the example. that's an normal html form and it does the login authentication. Its similar to gmail page – MDP Jan 05 '17 at 11:55
  • here are a couple of suggestions, depending a bit on exactly how the login page is implemented: http://stackoverflow.com/questions/3198105/including-login-credentials-with-a-webrequest, http://odetocode.com/articles/162.aspx I've never tried it myself so I wouldn't like to offer you a definitive solution. Basically you need to think how you would recreate the login request that a user would make if they used the site. And then retain the login cookie that's returned, for making future requests to the pages you actually want. – ADyson Jan 06 '17 at 09:42