2016-11-26 15 views
0

私はこの作品を作ることができません、私はすでにこれについていくつかのリンクを見たが、何も動作しません。私はそのURLからフォームトークンを取得する必要がありRegex html、入力値を取得

Ubuntuマシン(http://h.com/heya/login)によ:

$result = Invoke-WebRequest -Uri 'http://hey.com/heya/login' -SessionVariable tok 
$found = $result -match 'name="token" value="(.*?)"' 
$token = $matches[1] 

Write-Host $token # this is empty 

更新:コードは、PowerShellコンソール上で動作しますが、私のために働いていませんでしたpowershell -File file.ps1というコマンドでは、コードが間違っていると思いました。私がそれを更新した後には、うまくいったように働いた

答えて

2

Recommendation:最新のPowerShell Alphaにアップグレードしてください。この回答のコメントに基づいて、古いバージョンを実行しているようです。

Windows 10周年のアップデートでうまく動作します。

PS C:\Users\TrevorSullivan> $result = Invoke-WebRequest -Uri 'http://migueldvl.com/heya/login' -SessionVariable tok 
$found = $result -match 'name="token" value="(.*?)"' 
$token = $matches[1] 

Write-Host $token # this is empty 
80565711d0a74e6c0d29792ec2d029dc 

PS C:\Users\TrevorSullivan> $PSVersionTable 

Name       Value                        
----       -----                        
PSVersion      5.1.14393.206                      
PSEdition      Desktop                       
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0...}                   
BuildVersion     10.0.14393.206                      
CLRVersion      4.0.30319.42000                     
WSManStackVersion    3.0                        
PSRemotingProtocolVersion  2.3                        
SerializationVersion   1.1.0.1                       

enter image description here

EDIT:更新された質問に対応するために、私はまた、ドッカー環境の下では、Ubuntu 16.04 Xenial Xerusでこれをテストしました。そこにも働くようです。

enter image description here

PS /> $PSVersionTable 

Name       Value 
----       ----- 
PSVersion      6.0.0-alpha 
PSEdition      Core 
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0...} 
BuildVersion     3.0.0.0 
GitCommitId     v6.0.0-alpha.12 
CLRVersion 
WSManStackVersion    3.0 
PSRemotingProtocolVersion  2.3 
SerializationVersion   1.1.0.1 

私はPowerShellのバイナリに-Fileパラメータを使用する場合にも完全に正常に動作します。奇妙な出力を無視する - それはPowerShellホストの欠陥だと私は信じている。

enter image description here

+0

あなたはUbuntuの上でPowerShellのコアからスクリプトを呼び出している、またはあなたがPowerShellのデスクトップ版とWindowsシステム上でそれを呼び出していますか? –

+0

大丈夫、私はPowerShellコアでテストしていません。申し訳ありませんが、私はそれを試してみました - 私はあなたの元の質問(私は私の答えを投稿した時点でそれを編集したように見えます) :) –

+0

@Miguel私はちょうどPowerShellコア6.0.​​0アルファ12を実行しているDockerコンテナを使用してUbuntu 16でテストしました。私のために働くようです。 PowerShell Coreのどのバージョンを使用していますか?アップグレードしたいかもしれません。 –

関連する問題