英文:
How can I access the Apify SDK within the Pagefunction with PhantonJS Scraper
问题
我正在使用Apify Phanton爬虫。在PageFunction内,我想要访问Apify SDK,就像您可以在其他Apify cheerio-scraper和Apify puppeteer-scraper中做的那样。
我注意到PhantonJS爬虫上下文确实暴露了Apify对象,而其他爬虫则没有。
一个可能的解决方案是在pageFunction中注入jquery并使用Apify web API。
英文:
I am using the Apify Phanton crawler. Inside of the PageFunction, I would like to access the Apify SDK, which you can do with the other Apify cheerio-scraper and Apify puppeteer-scraper.
I noticed the PhantonJS crawler context does expose the Apify object, while the others do.
One possible solution would be to inject jquery in the pageFunction and use the Apify web API.
答案1
得分: 1
"Web Scraper"没有暴露Apify
变量,因为pageFunction
在浏览器上下文中运行,而SDK存在于Node.js(服务器)上下文中。您可以使用我们的API与fetch
或JQuery.ajax
一起使用。只需勾选disableWebSecurity
以解决CORS问题。
英文:
The phantom or Web Scraper doesn't expose the Apify
variable because the pageFunction runs in the browser context and the SDK exists in the Node.js (server) context. You can use our API with the fetch
or JQuery.ajax
. Just tick on the disableWebSecurity
so you get rid of CORS problems.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论