Is it possible to get HTML code with powershell ?

by Lecter at 2012-10-16 03:36:24

Hello

Is it possible to get HTML code of a webpage with powershell and save code to TXT file ?

Best Regards
L.
by Makovec at 2012-10-16 04:29:32
Yes, you can use .NET class NET.WebClient (talking about PowerShell v2, in v3 there is new cmdlet Invoke-WebRequest which can save you some time with parsing TXT file http://technet.microsoft.com/en-us/library/hh849901.aspx).

You can use .NET class this way:

$wc = New-Object Net.WebClient
$wc.DownloadString(‘http://www.bing.com’) | Out-File -FilePath c]
by Lecter at 2012-10-30 02:54:23
Hello

I’m trying to read frame content in powershell:


$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate2(“http://lala/perion/browse”)
while($ie.busy) {start-sleep 3}
($ie.Document.getElementsByTagName(“input”) | ? {$.name -eq ‘user’}).Value = ‘lala’
($ie.Document.getElementsByTagName(“input”) | ? {$
.name -eq ‘pass’}).Value = ‘lala’
($ie.Document.getElementsByTagName(“input”) | ? {$_.type -eq ‘submit’}).click()
$ie.Document.documentElement.all | d:\test\wd.txt


Steps:
1. new object
2. IE is visible
3. navigate to website
4. sleep because IE is opening
5. enter username
6. enter password
7. click “SUBMIT"
8. show all elements in CODE and write to filr

now I need contect of this frame a user uploaded image
This red frame…

in step 8 I have in file all elements

and I know that frame is under

src : /Hyperion/browse/browseList?

[quote]
tagName : FRAME
parentElement : System.__ComObject
style : System.__ComObject
onhelp :
onclick :
ondblclick :
onkeydown :
onkeyup :
onkeypress :
onmouseout :
onmouseover :
onmousemove :
onmousedown :
onmouseup :
document : System.__ComObject
title : Contenu
language :
onselectstart :
sourceIndex : 14
recordNumber :
lang :
offsetLeft : 144
offsetTop : 0
offsetWidth : 1292
offsetHeight : 650
offsetParent : System.__ComObject
innerHTML :
innerText :
outerHTML : <FRAME title=Contenu marginHeight=0 src=”/Hyperion/browse/browseList?" name=data marginWidth=0>
outerText :
parentTextEdit :
isTextEdit : False
filters :
ondragstart :
onbeforeupdate :
onafterupdate :
onerrorupdate :
onrowexit :
onrowenter :
ondatasetchanged :
ondataavailable :
ondatasetcomplete :
onfilterchange :
children : System.__ComObject
all : System.__ComObject
scopeName : HTML
onlosecapture :
onscroll :
ondrag :
ondragend :
ondragenter :
ondragover :
ondragleave :
ondrop :
onbeforecut :
oncut :
onbeforecopy :
oncopy :
onbeforepaste :
onpaste :
currentStyle : System.__ComObject
onpropertychange :
tabIndex : -32768
accessKey :
onblur :
onfocus :
onresize :
clientHeight : 650
clientWidth : 1292
clientTop : 0
clientLeft : 0
readyState : complete
onreadystatechange :
onrowsdelete :
onrowsinserted :
oncellchange :
dir :
scrollHeight : 650
scrollWidth : 1292
scrollTop : 0
scrollLeft : 0
oncontextmenu :
canHaveChildren : False
runtimeStyle : System.__ComObject
behaviorUrns : System.__ComObject
tagUrn :
onbeforeeditfocus :
readyStateValue :
isMultiLine : True
canHaveHTML : False
onlayoutcomplete :
onpage :
inflateBlock :
onbeforedeactivate :
contentEditable : inherit
isContentEditable : False
hideFocus : False
disabled : False
isDisabled : False
onmove :
oncontrolselect :
onresizestart :
onresizeend :
onmovestart :
onmoveend :
onmouseenter :
onmouseleave :
onactivate :
ondeactivate :
glyphMode :
onmousewheel :
onbeforeactivate :
onfocusin :
onfocusout :
uniqueNumber : 26
uniqueID : ms__id26
nodeType : 1
parentNode : System.__ComObject
childNodes : System.__ComObject
attributes : System.__ComObject
nodeName : FRAME
nodeValue :
firstChild :
lastChild :
previousSibling : System.__ComObject
nextSibling :
ownerDocument : System.__ComObject
dataFld :
dataSrc :
dataFormatAs :
role :
ariaBusy :
ariaChecked :
ariaDisabled :
ariaExpanded :
ariaHaspopup :
ariaHidden :
ariaInvalid :
ariaMultiselectable :
ariaPressed :
ariaReadonly :
ariaRequired :
ariaSecret :
ariaSelected :
ie8_attributes :
ariaValuenow :
ariaPosinset :
ariaSetsize :
ariaLevel :
ariaValuemin :
ariaValuemax :
ariaControls :
ariaDescribedby :
ariaFlowto :
ariaLabelledby :
ariaActivedescendant :
ariaOwns :
ariaLive :
ariaRelevant :
constructor :
src : /Hyperion/browse/browseList?
name : data
border :
frameBorder :
frameSpacing :
marginWidth : 0
marginHeight : 0
noResize : False
scrolling : auto
contentWindow :
onload :
allowTransparency : False
longDesc :
borderColor :
height : 650
width : 1292
contentDocument :
ie8_src :
ie8_longDesc :
ie8_frameBorder :

[/quote]

So how to enter DEEPER and enter this frame and get code for this frame ?

Best Regards
L
by Jason_Yoder_MCT at 2012-10-30 06:58:53
Here is the code that I use to download the source information from a web page.

Function Download-HTML
{
[CmdletBinding(HelpUri="http]
Param(
[Parameter(Mandatory=$True)]$Source,
[Parameter(Mandatory=$True)]$SaveFile,
[Switch]$Quiet

)

#Create an object to hold the web content.
$DataObj = New-Object System.Net.WebClient


Try
{
# Use the System.Net.WebClient method: Download to attempt to
# download the data. If it dows not exists, then error out.
$DataObj.DownloadFile(“Http://$source”, $SaveFile)

# Once the file is found, notify the user if $Quite is $False.
If ($Quiet-eq $False)
{
Write-Host “Website text downloaded to $SaveFile” -foreground Green -background DarkGreen
}
}
Catch
{
# If the file is not available and the code errors, let the user
# know the file is not there unless $Quest is $True.
If ($Quiet-eq $False)
{
Write-Host “File not Available” -ForegroundColor Red -BackgroundColor DarkRed
}
}
<#
.SYNOPSIS
Saves HTML source code from the web to a file on your hard drive.

.DESCRIPTION
Allows you to specify a website and download the source code.

.PARAMETER Source
The website that you want to download the source code from.

.PARAMETER SaveFile
The destination path and file name that you want to save the source code to.

.PARAMETER Quiet
Suppresses on screen messages.

.EXAMPLE
Download-HTML -Source “www.MCTExpert.com” -SaveFile "C:\Data\Code.html"

Downloads the code from the web page http://www.MCTExpert.com and saves it to the
local hard drive in the Data folder as Code.html.

#>
}