PowerShell-HTML解析:从网站获取信息 [英] PowerShell - HTML parsing: get information from a website
本文介绍了PowerShell-HTML解析:从网站获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更新,脚本正在使用PowerShell V3.0,谢谢@ Doug
我想使用以下PowerShell脚本从汉莎航空获取航班状态信息. 我可以在浏览器中看到航班状态信息,但找不到任何通过脚本访问此信息的方法.
I want to use the following PowerShell script to get flight status information from Lufthansa. I can see flight status information in the browser, but I haven't found any way to access this information with my script.
我想从网站上获得以下信息:
I want to get the following information from the website:
- 航班状态
- 时间(出发,到达)
- 机场(出发,到达)
- 航班号(仅汉莎航空)
脚本:
$flight = " LH3396"
$url = "http://bing.com?q=flight status for $flight"
$result = Invoke-WebRequest $url
$elements = $result.AllElements | Where Class -eq "ans" | Select -First 1 -ExpandProperty innerText
#[string[]]$resultArray
$resultArray = @()
foreach($element in $elements.Split("`n")){
if($element.Length -gt "2")
{$resultArray += $element}
}
推荐答案
这是在PowerShell v3中查询Bing的一种方式
Here is a way to query Bing in PowerShell v3
function Get-FlightStatus {
param($query)
$url = "http://bing.com?q=flight status for $query"
$result = Invoke-WebRequest $url
$result.AllElements |
Where Class -eq "ans" |
Select -First 1 -ExpandProperty innerText
}
Get-FlightStatus LH3102
Flight status for Lufthansa 3102
To depart · Jan 30, 2012
From: Hamburg (HAM) 05:35 PM terminal 2
To: Vienna (VIE) 07:05 PM
Bing Travel Source: www.flightstats.com, 1 minute ago
这篇关于PowerShell-HTML解析:从网站获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文