我正在尝试保存需要会话登录的网页内容;我尝试将 wget 与用户代理和用户名(e/login)和密码(p/password)输入一起使用,并尝试保存 cookie 文件,但意识到没有写入任何内容。然后我继续使用此方法(在PowerShell 6):
$R = Invoke-WebRequest -Uri "https://app.asana.com/-/login" -UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0" -SessionVariable asana
但是当我尝试的时候
$Form = $R.Forms[0]
没有表格。
Cannot index into a null array.
At line:1 char:1
+ $Form = $R.Forms[0]
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
输入字段如下:
$R.InputFields
outerHTML : <input type="hidden" name="u" value="https://app.asana.com/?rr=296832" />
tagName : INPUT
type : hidden
name : u
value : https://app.asana.com/?rr=296832
outerHTML : <input type="hidden" name="i" value="password" />
tagName : INPUT
type : hidden
name : i
value : password
outerHTML : <input type="hidden" name="src" value="login" />
tagName : INPUT
type : hidden
name : src
value : login
outerHTML : <input type="hidden" name="auth" />
tagName : INPUT
type : hidden
name : auth
outerHTML : <input type="hidden" name="xsrf_token" value="60a3a8255cfe364b3fbec08ec6c2106e:1578648571483" />
tagName : INPUT
type : hidden
name : xsrf_token
value : 60a3a8255cfe364b3fbec08ec6c2106e:1578648571483
outerHTML : <input tabindex="1" type="email" name="e" id="email_input" value="" />
tagName : INPUT
tabindex : 1
type : email
name : e
id : email_input
value :
outerHTML : <input tabindex="2" type="password" name="p" id="password_input" />
tagName : INPUT
tabindex : 2
type : password
name : p
id : password_input
所以现在我可以直接访问用户名(即电子邮件):
$R.InputFields[5].Value="nats@email"
但是 InputFields[6] 没有 Value 属性,即密码。
Exception setting "Value": "The property 'Value' cannot be found on this object. Verify that the property exists and can be set."
我想不出另一种输入密码的方法。或者也许有完全不同的方法?
登录后,我将访问我想要的网页(在会话中)并使用 -OutFile.. 保存内容。