本帖最后由 xiaooooooo 于 2023-8-3 09:48 编辑
想请教一下各位大佬,我下面两种方法都失败了,但是我调试部分可以成功拿到元素,问题是出在哪里?
调试链接:https://www.jetstar.com/cn/zh/home?adults=1&children=0&destination=SYD&flexible=1&flight-type=1&infants=0&origin=MEL&selected-departure-date=09-08-2023&tab=1
// ==UserScript==
// @match https://booking.jetstar.com/cn/zh/booking/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=jetstar.com
// @require http://cdn.bootcss.com/jquery/1.11.2/jquery.js
// @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
'use strict';
————————调试部分————————
elmGetter.selector($);
elmGetter.selector('css');
const wenzi = document.querySelector("div.display-currency-AUD > div:nth-child(3) > div.columns > div.js-fare-row > div.js-fare-row-summary > div.flight-card-itinerary > div.flight-card-itinerary-row > div:nth-child(1) > div.js-departure-time")
elmGetter.each('*', wenzi, el => {
console.log(el.cloneNode(true));
console.log($(wenzi).text());//这个就是我想要得到的结果
});
————————调试部分结束————————
————————方法一:想从上往下找子元素————————
elmGetter.each('div.display-currency-AUD div.row', company_name => {
console.info('page is fully loaded');
var dataList = [];
for (var i=2; i<company_name.length; i++){
var shijian = $(company_name[i]).find('div.columns div.js-fare-row div.js-fare-row-summary div.flight-card-itinerary div.flight-card-itinerary-row').eq(0).find('div.js-departure-time').text()
dataList.push({
'shijian': shijian
})
}
console.info(dataList);
});
————————方法一结束————————
————————方法二:想从子元素自己找父级————————
elmGetter.each('div.row', column1 => {
const company_name = column1.parent();
console.info('page is fully loaded');
var dataList = [];
for (var i=2; i<company_name.length; i++){
var shijian = $(company_name[i]).find('div.columns div.js-fare-row div.js-fare-row-summary div.flight-card-itinerary div.flight-card-itinerary-row').eq(0).find('div.js-departure-time').text()
dataList.push({
'shijian': shijian
})
}
console.info(dataList);
});
————————方法二结束————————
})();