如何在PhantomJS Scraper中的Pagefunction内访问Apify SDK?

huangapple go评论115阅读模式
英文:

How can I access the Apify SDK within the Pagefunction with PhantonJS Scraper

问题

我正在使用Apify Phanton爬虫。在PageFunction内,我想要访问Apify SDK,就像您可以在其他Apify cheerio-scraperApify 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与fetchJQuery.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.

huangapple
  • 本文由 发表于 2020年1月3日 21:06:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579153.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定