リクエストを使用してフォームを送信し、結果の Web ページをダウンロードしようとしています。問題は、ブラウザでフォームに入力したときに表示されるページの大部分が、ダウンロードされたページに表示されないことです。
aa.com でシート マップを表示しようとしています。実際のシートマップ以外はほとんど揃っています。
from requests import session
def get_page():
payload = {
'airportLookupRequired': 'true',
'currentCodeForm': 'originAirport',
'currentCalForm': 'viewSeatsForm',
'flightNumber': '1132',
'departureMonth': '9',
'departureDay': '22',
'originAirport': 'dfw',
'destinationAirport': 'lga',
'cabin': 'coach',
'_button_submit': 'GO'
}
with session() as c:
c.post('https://www.aa.com/seatmap/viewSeatsAccess.do', payload)
r = c.get('https://www.aa.com/seatmap/viewSeatsSubmit.do')
print r.content.replace('/content/images', 'https://www.aa.com/content/images')
get_page()
これを修正するための提案、または機能しない理由を理解するための提案をいただければ幸いです。
編集:ブラウザツールを使用してAJAXリクエストを探すとわかります
Resource interpreted as Script but transferred with MIME type text/plain: "https://www.aa.com/dwr/interface/SeatMapAjaxUtils.js". viewSeatsSubmit.do:52
それをクリックすると、次のようになります。
// Provide a default path to dwr.engine
if (dwr == null) var dwr = {};
if (dwr.engine == null) dwr.engine = {};
if (DWREngine == null) var DWREngine = dwr.engine;
if (SeatMapAjaxUtils == null) var SeatMapAjaxUtils = {};
SeatMapAjaxUtils._path = '/dwr';
SeatMapAjaxUtils.formatAmount = function(p0, p1, callback) {
dwr.engine._execute(SeatMapAjaxUtils._path, 'SeatMapAjaxUtils', 'formatAmount', p0, p1, callback);
}
SeatMapAjaxUtils.getExitRowSeatSelectionResponse = function(p0, callback) {
dwr.engine._execute(SeatMapAjaxUtils._path, 'SeatMapAjaxUtils', 'getExitRowSeatSelectionResponse', p0, callback);
}
これは、必要な情報を生成するコードのようです。そこからどう進めばいいのかわからない。