简体   繁体   English

使用 AJAX 请求抓取页面

[英]Scrape a page with AJAX requests

I'm using Node.js with jsDOM to scrape web pages and execute JavaScript in them.我正在使用 Node.js 和 jsDOM 来抓取 web 页面并在其中执行 JavaScript 。 But if a page contains AJAX requests, they are not executed.但是如果一个页面包含 AJAX 请求,它们不会被执行。

Is there an option to execute AJAX calls inside the scraped pages?是否可以选择在抓取的页面内执行 AJAX 调用?

you need to emulate XMLHTTPRequests.您需要模拟 XMLHTTPRequests。 Here's an abstraction .这是一个抽象 They don't work out of the box in node.js.它们在 node.js 中不能开箱即用。

You will have to figure out how to get it to talk to jsdom.你必须弄清楚如何让它与 jsdom 对话。 (Hopefully just appending a xmlhttprequest constructor to the window will fix it) (希望只是将 xmlhttprequest 构造函数附加到window将修复它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM