apefify如何停止在浏览器中打开新页面的Enqueuelink函数
我正在尝试从页面获得链接,然后通过单击按钮导航到下一页。问题是我首先需要将第一页上的所有链接添加到队列中,但是当我尝试单击元素时,Enqueuelist函数似乎启动了一个新页面,从而导致“未找到错误”。 任何建议都会有所帮助!
exports.handleList = async ({ request, page }, requestQueue) => {
await Apify.utils.enqueueLinks({
page: page,
requestQueue: requestQueue,
selector: "#traziPoduzeca > tbody > tr > td > span > a",
baseUrl: "https://www.fininfo.hr/Poduzece/[.*]",
transformRequestFunction: (request) => {
request.userData = {
label: "DETAIL",
};
return request;
},
});
log.info('about to scrap urls')
await page.waitForTimeout(120);
let btn_selector =
"//div[@class='contentNav'][1]//div[@class='pagination'][1]//span[@class='current']/following-sibling::a";
let buttonEle = await page.$x(btn_selector);
log.info(`length of pagination is ${buttonEle.length}`);
for (let index = 0; index < buttonEle.length; index++) {
await page.waitForTimeout(120);
await buttonEle[index].click();
log.info("clicked");
await page.waitForTimeout(200);
await Apify.utils.enqueueLinks({
page: page,
requestQueue: requestQueue,
selector: "#traziPoduzeca > tbody > tr > td > span > a",
baseUrl: "https://www.fininfo.hr/Poduzece/[.*]",
transformRequestFunction: (request) => {
request.userData = {
label: "DETAIL",
};
return request;
},
});
}
};
I am trying to get links from a page and then navigate to the next page through a click of a button. The issue is I first need to add all the links on the first page to a queue however the enqueueList function seems to start a new page, causing a "Node not found error" when I try to click on an element.
Any advice would be helpful!
exports.handleList = async ({ request, page }, requestQueue) => {
await Apify.utils.enqueueLinks({
page: page,
requestQueue: requestQueue,
selector: "#traziPoduzeca > tbody > tr > td > span > a",
baseUrl: "https://www.fininfo.hr/Poduzece/[.*]",
transformRequestFunction: (request) => {
request.userData = {
label: "DETAIL",
};
return request;
},
});
log.info('about to scrap urls')
await page.waitForTimeout(120);
let btn_selector =
"//div[@class='contentNav'][1]//div[@class='pagination'][1]//span[@class='current']/following-sibling::a";
let buttonEle = await page.$x(btn_selector);
log.info(`length of pagination is ${buttonEle.length}`);
for (let index = 0; index < buttonEle.length; index++) {
await page.waitForTimeout(120);
await buttonEle[index].click();
log.info("clicked");
await page.waitForTimeout(200);
await Apify.utils.enqueueLinks({
page: page,
requestQueue: requestQueue,
selector: "#traziPoduzeca > tbody > tr > td > span > a",
baseUrl: "https://www.fininfo.hr/Poduzece/[.*]",
transformRequestFunction: (request) => {
request.userData = {
label: "DETAIL",
};
return request;
},
});
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导致错误的不是
Enqueuelinks
函数。如果您想留在同一页面上,则需要等待导航,类似的事情:It's not the
enqueueLinks
function that is causing the error, is the navigation that is happening. You need to await for the navigation if you want to stay on the same page, something like this: