木偶不加载完整的页面渲染
我正在尝试从MT5服务器刮擦。在我的浏览器上,网站显示加载几秒钟或毫秒,然后呈现登录表单。但是没有木偶。只是永远的加载页面,直到超时。而且,当我尝试编码木偶时,等待元素呈现后,时间暂停后就会崩溃。我已经尝试了不同的方法来找出出了什么问题(其中一些我在代码中评论了)。我不知道我在哪里弄错了,还是从网站上弄错了?
这也是我第一次使用木偶。 我的代码在下面。有什么人可以帮助我解决解决方案吗?
const puppeteer = require("puppeteer");
const baseUrl = "https://trade.mql5.com/trade?servers=";
const getData = async () => {
console.log(baseUrl);
// launch pupprteer
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// await page.setDefaultNavigationTimeout(60000);
await page.goto(baseUrl, { waitUntil: "networkidle2", timeout: 0 });
// await page.waitForNavigation(() =>
// document.querySelector("#hero-head-circle")
// );
// await page.screenshot({ path: "login.png" });
await page.waitForSelector("#login"),
await page.screenshot({ path: "login.png" });
await browser.close();
};
getData();
I am trying to scrape from an MT5 server. On my browser the site shows loading for a few seconds or milliseconds then renders the login form. But with puppeter it doesn't. Just the loading page like forever, till timeout. And when i try to code puppeteer wait until the element is rendered it crashes after timeout. I have tried different methods to find out whats wrong(Some of which i commented out in my code). I don't know where i got it wrong or is it from the site?
This is my first time using Puppeteer too.
My Code is below. Any body that can help me out with solutions?
const puppeteer = require("puppeteer");
const baseUrl = "https://trade.mql5.com/trade?servers=";
const getData = async () => {
console.log(baseUrl);
// launch pupprteer
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// await page.setDefaultNavigationTimeout(60000);
await page.goto(baseUrl, { waitUntil: "networkidle2", timeout: 0 });
// await page.waitForNavigation(() =>
// document.querySelector("#hero-head-circle")
// );
// await page.screenshot({ path: "login.png" });
await page.waitForSelector("#login"),
await page.screenshot({ path: "login.png" });
await browser.close();
};
getData();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为我遇到了同样的问题,当您向下滚动时,某些页面加载内容,因此,除非您向下滚动,否则选择器#login可能不会贴上苹果。如果是问题,请尝试使用此代码:
这为我解决了问题。请记住,您可能必须根据所使用的页面更改“大小”和“延迟”。
I think i had the same issue, somepages load content as you scroll down through them, so the selector #login may not be apppering unless you scroll down; if that is the issue try with this code:
This solved the issue for me. Have in mind that you may have to change "size" and "delay" depending on the page that you are using.