我想从这个 url 中抓取所有的 alertDetails -
https://www.oref.org.il/12481-en/Pakar.aspx
我写了这段代码,但我认为是因为“在过去一周”不活跃,它找不到我搜索的警报详细信息。
如何激活过去一周的课程?`
const PORT = 8000
const axios = require('axios')
const cheerio = require('cheerio')
const express = require('express')
const app = express()
const url = 'https://www.oref.org.il/12481-en/Pakar.aspx'
axios(url)
.then(response => {
const html = response.data
const $ = cheerio.load(html)
const alerts = []
$('.alertDetails', html).each(function() {
const alert = $(this).text()
alerts.push({
alert
})
})
console.log(alerts)
}).catch(err => console.log(err))
app.listen(PORT, () => console.log(`server running on PORT ${PORT}`))
您可以使用浏览器 DevTools 查看在单击“过去一周”按钮(在网络选项卡下)时如何获取数据。它比操作页面 HTML 页面要容易得多。
获取“过去一周”的警报列表,您应该从
https://www.oref.org.il//Shared/Ajax/GetAlarmsHistory.aspx?lang=en&mode=2
获取响应。
要获取特定日期范围内的警报列表(例如 5 月 1 日至 5 月 7 日),您需要从
https://www.oref.org.il//Shared/Ajax/GetAlarmsHistory.aspx?lang=en&fromDate=01.05.2023&toDate=07.05.2023&mode=0
等获取响应
只需使用 DevTool 并从网络选项卡中查看外出呼叫