为什么这个 scrape return 未定义?
Why does this scrape return undefined?
当我 运行 这段代码时,我得到了未定义但很明显滑雪板和 product_id 处于值形式。
我要:
value="BTdtb4CBz3uSJ2qv"
value="adi-ss20-042"
但我得到“未定义”
class TresBien {
async scrapeRaffleInfo() {
// scrape the form_key and sku values
const response = await axios(
"https://tres-bien.com/adidas-yeezy-boost-380-mist-fx9764-ss20"
);
console.log("response: ", response);
const html = await response.data;
const $ = cheerio.load(html);
const res = $('input[name="sku"]').val();
const ans = $('input[name="form_key"]').val();
console.log(res && ans);
}
}
const main = async () => {
const tb = new TresBien(
"https://tres-bien.com/adidas-yeezy-700-v3-alvah-h67799-ss20"
);
let checkoutSucc = await tb.scrapeRaffleInfo();
if (checkoutSucc) {
Logger.logEventSuccess("Raffle successfully entered");
}
};
main();
您的代码中存在一些错误:
- 如@Pointy 所述,
scrapeRaffleInfo()
返回未定义,而您正试图在 checkoutSucc
中使用它
- Tresbien class 不提供任何构造函数,但您将 url 作为参数传递给 class 的构造函数。
- 您没有使用任何
axios
库方法(例如:get()
、post()
、put()
、delete()
)。通常你需要 axios.get()
但在你的代码中,你只是使用 axios()
当我 运行 这段代码时,我得到了未定义但很明显滑雪板和 product_id 处于值形式。
我要:
value="BTdtb4CBz3uSJ2qv"
value="adi-ss20-042"
但我得到“未定义”
class TresBien {
async scrapeRaffleInfo() {
// scrape the form_key and sku values
const response = await axios(
"https://tres-bien.com/adidas-yeezy-boost-380-mist-fx9764-ss20"
);
console.log("response: ", response);
const html = await response.data;
const $ = cheerio.load(html);
const res = $('input[name="sku"]').val();
const ans = $('input[name="form_key"]').val();
console.log(res && ans);
}
}
const main = async () => {
const tb = new TresBien(
"https://tres-bien.com/adidas-yeezy-700-v3-alvah-h67799-ss20"
);
let checkoutSucc = await tb.scrapeRaffleInfo();
if (checkoutSucc) {
Logger.logEventSuccess("Raffle successfully entered");
}
};
main();
您的代码中存在一些错误:
- 如@Pointy 所述,
scrapeRaffleInfo()
返回未定义,而您正试图在checkoutSucc
中使用它
- Tresbien class 不提供任何构造函数,但您将 url 作为参数传递给 class 的构造函数。
- 您没有使用任何
axios
库方法(例如:get()
、post()
、put()
、delete()
)。通常你需要axios.get()
但在你的代码中,你只是使用axios()