2020-07-20 POWERSHELL 查询股票行情
2020-07-20 本文已影响0人
莫希子西
$array = "000908","002480"
foreach ($stockCode in $array)
{
if ($stockCode -eq ""){
Write-Host "Please input code!"
exit
}
if($stockCode -match '^60*')
{
$stockCode= "sh" + $stockCode
}
elseif($stockCode -match '^00*')
{
$stockCode= "sz" + $stockCode
}
elseif($stockCode -match '^300*')
{
$stockCode= "sz" + $stockCode
}
else {
Write-Host "Error, Please try again!"
exit
}
$sourceURL="http://hq.sinajs.cn/list=$stockCode"
$wc=New-Object system.net.webclient
$content=$wc.downloadstring($sourceURL)
$str_splits=$content.Split(',');
$stockName=$str_splits[0].split('"')
Write-Host
$myStock=$stockName[1]
$lastPrice=$str_splits[2]
$nowPrice=$str_splits[3]
$higePrice=$str_splits[4]
$lowPrice= $str_splits[5]
$priceP=($nowPrice - $lastPrice )/$lastPrice
[double] $a="{0:0.####}" -f $priceP
$b="{0:p}" -f $a
if($lastPrice -gt $nowPrice )
{
$myColor="Green"
}
else
{
$myColor="Red"
}
Write-Host -ForegroundColor $myColor "$myStock `t Now: $nowPrice `t`t Hign:$higePrice `t Low:$lowPrice `t ZD%:$b"
}
Write-Host
$sourceURL="http://hq.sinajs.cn/list=s_sh000001"
$wc=New-Object system.net.webclient
$content=$wc.downloadstring($sourceURL)
$str_splits=$content.Split(',');
$nowPrice=$str_splits[1]
$ricePrice=$str_splits[2]
$ricePriceP=$str_splits[3]
$shmon=$str_splits[5].Replace('";','')
if($ricePrice -match '^-')
{
$myColor="Green"
}
else
{
$myColor="Red"
}
Write-Host -ForegroundColor $myColor "999999 `t Now: $nowPrice `t ZD: $ricePrice `t ZD%:$ricePriceP `t Amount(WAN):$shmon"
$sourceURL="http://hq.sinajs.cn/list=s_sz399001"
$wc=New-Object system.net.webclient
$content=$wc.downloadstring($sourceURL)
$str_splits=$content.Split(',')
$nowPrice=$str_splits[1]
$ricePrice=$str_splits[2]
$ricePriceP=$str_splits[3]
$szmon=$str_splits[5].Replace('";','')
if($ricePrice -match '^-')
{
$myColor="Green"
}
else
{
$myColor="Red"
}
Write-Host -ForegroundColor $myColor "399001 `t Now: $nowPrice `t ZD: $ricePrice `t ZD%:$ricePriceP `t Amount(WAN):$szmon"
$sourceURL="http://hq.sinajs.cn/list=s_sz399006"
$wc=New-Object system.net.webclient
$content=$wc.downloadstring($sourceURL)
$str_splits=$content.Split(',')
$nowPrice=$str_splits[1]
$ricePrice=$str_splits[2]
$ricePriceP=$str_splits[3]
$cymon=$str_splits[5].Replace('";','')
if($ricePrice -match '^-')
{
$myColor="Green"
}
else
{
$myColor="Red"
}
Write-Host -ForegroundColor $myColor "399006`t Now: $nowPrice `t ZD: $ricePrice `t ZD%:$ricePriceP `t Amount(WAN):$cymon"
$totalAmount = ([INT]$shmon+[INT]$szmon+[INT]$cymon)/10000
echo Total $totalAmount
Start-Sleep 10
最后出现结果如下: