【发布时间】:2014-08-17 05:11:12
【问题描述】:
我的问题陈述是这样的——我需要从门户网站中提取所有酒店名称和相应的价格。如果不是通过脚本,这对我来说是一个乏味的手动过程。
例如,在以下 URL 上,我需要所有酒店的名称和相应的价格:http://hotel.makemytrip.com/makemytrip/site/hotels/search?session_cId=1403778791562&city=SLV&country=IN&checkin=06282014&checkout=06302014&area=&roomStayQualifier=1e0e&type=&sortName=&searchText=&isBaitNWait=null&fullSearch=false
期望的输出:
Hotel Name Price
Oberoi Wildflower Hall 16,500
Hotel Chaman Palace 1,879
我是用 Powershell 语言做的。基本上我需要了解如何获得一个占位符(酒店名称或价格)的价值。到目前为止,我已经尝试过了。
$surl="http://hotel.makemytrip.com/makemytrip/site/hotels/search?session_cId=1403778791562&city=SLV&country=IN&checkin=06282014&checkout=06302014&area=&roomStayQualifier=1e0e&type=&sortName=&searchText=&isBaitNWait=null&fullSearch=false"
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($surl)
$doc = $ie.Document
$element = $doc.getElementsByClassName("hotelImgLkflL")
$element > d:\element.txt
但是,我收到以下错误消息。
您不能在空值表达式上调用方法。
Update : 现在我正在尝试通过$web.DownloadString 进行操作,并发现所有酒店名称的来源都具有以下模式:
id="200701171240402395" title="Oberoi Wildflower Hall" href="/makemytrip/site/hotels/detail?
id="201111211716292072" title="Hotel Chaman Palace" href="/makemytrip/site/hotels/detail?
id="200701121106345886" title="Hotel Baljees Regency" href="/makemytrip/site/hotels/detail?
我现在该怎么做?谢谢。
感谢任何指导。
【问题讨论】:
标签: html .net powershell scripting