1

The page I am trying to save uses relative links. I am saving this file to another location and need the file to have absolute links.

I have tried the following Powershell command:

$client = new-object System.Net.WebClient
$client.DownloadFile( "http://www.WEBSITE.com/ExampleFolder/", "c:\Test.htm")

This works for downloading and saving the page, but... It opens from the root directory (ex: file:///C:/ExampleFolder/linktofile.asp).

I have tried manually saving the page and was able to get my desired results by saving it as "Webpage Complete" (as opposed to "Webpage HTML only"). This task needs to be done daily, so I unfortunately can't do it manually.

SideNote: I am using Powershell 2.0.1.1

majestzim
  • 518
  • 6
  • 16
  • I recieved some help and was able to actually come up with a solution in VBScript. I'll post my code later (since I can't at the moment), but I would still be interested in a solution using Powershell. – majestzim Feb 28 '14 at 21:13
  • In case someone is looking to do this using wget: http://stackoverflow.com/questions/6348289/download-a-working-local-copy-of-a-webpage – hcarreras Nov 24 '15 at 11:01

2 Answers2

0

I dont think you can change the content of the HTML page, without parsing the .innherHTML element and adding references to the root ().

This option is not available natively using the commands you mentioned for V2 or 3/4

0

This is the code I mentioned that would accomplish my request in VBScript:

myURL = "http://www.WEBSITE.com/ExampleFolder/"
outFile="c:\Test.htm"

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send
intStatus = objHTTP.Status

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write Replace(objHTTP.ResponseText,"/ExampleFolder/", "http://www.WEBSITE.com/ExampleFolder/") 
objFile.Close
majestzim
  • 518
  • 6
  • 16