【发布时间】:2020-09-16 09:07:18
【问题描述】:
我有一个调用 ajax 的网站在单击按钮时会加载更多数据。 在这种情况下,我使用 ajax 来调用加载更多数据。 分页也是如此。 我的代码如下:
function callAj(page) {
context.log.info('load page : ' + page);
// This log can show when I run the task.
fetch("url", {
"headers": {
"accept": "*/*",
"accept-language": "vi,en-US;q=0.9,en;q=0.8",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
"body": "action=load_more&sid=6&cid=9&orderby=date&order=DESC&size=9&ex=false" + "&pg=" + page,
"method": "POST"
}).then(res => res.text())
.then(data => {
if (data != '') {
// This log can't show when I run the task.
context.log.info('data in here can't not show: ' + data);
$('#id').append(data); page++; callAj(page);
}
})
}
当我在 chrome 开发者的控制台中调用 ajax 时,它仍然可以正常工作。但是在 Apify 我无法运行它 如何解决?
【问题讨论】:
-
您能否提供更多信息,为什么您无法运行它?在 Web Scraper 中(pageFunction 在浏览器上下文中),它应该开箱即用。理想情况下,我会让一切都异步/等待,它在 Web Scraper 之外更干净,你需要在 Puppeteer 的 page.evaluate() 中运行它
标签: apify