我一直在与Powershell打交道一个月左右。我对编码和Powershell很陌生。
我用Google搜索了如何使用Invoke-WebRequest
https://technet.microsoft.com/en-us/library/hh849901.aspx
或
https://gist.github.com/haraldfianbakken/32d5ac624c842a766df3
我试图用两个链接做同样的事情。
所以我制作了一个剧本。
$r = Invoke-WebRequest "https://idp.appery.io/idp/" -SessionVariable ws;
$r|Get-Member
它回应了
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
BaseResponse Property System.Net.WebResponse BaseResponse {get;set;}
Content Property byte[] Content {get;}
Headers Property System.Collections.Generic.Dictionary[string,string] Headers {get;}
RawContent Property string RawContent {get;}
RawContentLength Property long RawContentLength {get;}
RawContentStream Property System.IO.MemoryStream RawContentStream {get;}
StatusCode Property int StatusCode {get;}
StatusDescription Property string StatusDescription {get;}
根据这些网站,它应该有一个表格。
所以我可以这样做
$
r=Invoke-WebRequest http://www.facebook.com/login.php -SessionVariable fb
# Use the session variable that you created in Example 1. Output displays values for Headers, Cookies, Credentials, etc.
$fb
# Gets the first form in the Forms property of the HTTP response object in the $r variable, and saves it in the $form variable.
$form = $r.Forms[0]
# Pipes the form properties that are stored in the $forms variable into the Format-List cmdlet, to display those properties in a list.
$form | Format-List
# Displays the keys and values in the hash table (dictionary) object in the Fields property of the form.
$form.fields
# The next two commands populate the values of the "email" and "pass" keys of the hash table in the Fields property of the form. Of course, you can replace the email and password with values that you want to use.
$form.Fields["email"] = "User01@Fabrikam.com"
$form.Fields["pass"] = "P@ssw0rd"
我想与上面的代码完全相同,但是,我在https://idp.appery.io/idp/上看不到“表单”,当我看到网站时,有表格可以输入我的凭据,但当我做$ r | gm时,“表格”没有出现。
有没有出现任何理由?
是否有其他方式来放置我的凭证,所以我可以做同样的事情,如两个网站?
非常感谢你。
答案 0 :(得分:1)
我在我的对象中获得了表单。根据文档,您只能获得那里的内容。
在我尝试谷歌的时候:
PS C:\Users\Administrator> Invoke-WebRequest -Uri google.com | gm
TypeName: Microsoft.PowerShell.Commands.HtmlWebResponseObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AllElements Property Microsoft.PowerShell.Commands.WebCmdletElementCollection AllElements {get;}
BaseResponse Property System.Net.WebResponse BaseResponse {get;set;}
Content Property string Content {get;}
Forms Property Microsoft.PowerShell.Commands.FormObjectCollection Forms {get;}
Headers Property System.Collections.Generic.Dictionary[string,string] Headers {get;}
Images Property Microsoft.PowerShell.Commands.WebCmdletElementCollection Images {get;}
InputFields Property Microsoft.PowerShell.Commands.WebCmdletElementCollection InputFields {get;}
Links Property Microsoft.PowerShell.Commands.WebCmdletElementCollection Links {get;}
ParsedHtml Property mshtml.IHTMLDocument2 ParsedHtml {get;}
RawContent Property string RawContent {get;}
RawContentLength Property long RawContentLength {get;}
RawContentStream Property System.IO.MemoryStream RawContentStream {get;}
Scripts Property Microsoft.PowerShell.Commands.WebCmdletElementCollection Scripts {get;}
StatusCode Property int StatusCode {get;}
StatusDescription Property string StatusDescription {get;}
当我尝试您正在谈论的网站时,我甚至都不会收到HtmlWebResponse对象。
在这种情况下,尝试使用IE自动化后的自动化可能会更好。