我正在尝试使用请求提交表单并下载生成的网页。问题是,当我在浏览器上填写表单时,下载的页面缺少我看到的页面的大部分内容。
我正在尝试在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);
}
似乎是生成我想要的信息的代码。我不知道如何从那里开始。