0

我试图从 Booking.com 上获取酒店价格,现在得到一个奇怪的响应正文,这与我在私人模式下在浏览器上看到的不同。

当你运行下面的谷歌脚本时,你会得到“2178”日元,而在私人模式下点击地址栏上的相同网址,你会看到“2420”日元。

function myfunction() {
  
  var destid = '2658464'; 
  var year = '2018';
  var checkin_month = '12';
  var checkin_monthday = '20';
  var checkout_month = '12';
  var checkout_monthday = '21';
  
  var url = 'https://www.booking.com/searchresults.en-gb.html?checkin_year=' + year + '&checkin_month=' 
  + checkin_month + '&checkin_monthday=' + checkin_monthday + '&checkout_year=' + year + '&checkout_month=' + checkout_month + '&checkout_monthday=' + checkout_monthday 
    + '&no_rooms=1&group_adults=1&group_children=0&dest_id=' + destid + '&dest_type=hotel&selected_currency=JPY';
  
  Logger.log(url);
  
  var html = UrlFetchApp.fetch(url).getContentText();
  // Retrieve 'div' that contains the top search result
  var res = Parser.data(html).from("<span class=\"sr-hotel__name").to("class=\"sr_item sr_item_new sr_item_default").build().trim();
  var price;
  
  if ( res.indexOf('sold out on') != -1 ) { //when sold out on specified date
    Logger.log( 'SOLD OUT' );
  } else if ( res.indexOf('Dormitory') != -1 && res.indexOf( destid ) != -1 ){ //if its dormitory room and contains specified destId

    // retrieve price value in <b> tag
    price = Parser.data(res).from("<b>\n¥").to("</b>").build().trim().replace(new RegExp('[^0-9]', 'g'), '');
    Logger.log('Price: ' + price);

  } else {
    Logger.log( 'SOLD OUT' );
  }
  
}

基本上,Booking.com 根据当前登录用户的忠诚度级别(称为 Genius Booker)显示折扣价。我的脚本以某种方式检索折扣价,即使提供了任何凭据。

在大多数情况下,我的脚本可以很好地显示原始价格,但对于某些酒店,它会为 Genius 预订者返回折扣价。

你认为这是怎么发生的,有没有办法强制脚本总是返回原价?

谢谢你的时间。

4

0 回答 0