使用nodejs和phantomjs进行动态抓取
Dynamic scraping using nodejs and phantomjs
首先,我已经成功安装了PhantomJs及其npm接口phantom。我已经设置了用新语法加载页面的代码(这里发布的所有其他问题都是基于旧代码语法的,或者我遗漏了一些东西)。这就是我想要搜集的资料来源。
现在,右侧边栏、在"Comune"附近有假选择的边栏和另一个边栏都是动态生成的,我不明白为什么phantomjs没有拾取它们。遵循我的代码:
var sito = "http://bicincitta.tobike.it/";
var sitepage = null;
var phInstance = null;
var phantom = require('phantom')
phantom.create()
.then((instance) => {
phInstance = instance;
return instance.createPage();
})
.then((page) => {
sitepage = page;
return page.open(sito);
})
.then((status) => {
console.log(status);
return sitepage.property('content');
})
.then((content) => {
console.log(content);
sitepage.close();
phInstance.exit();
})
.catch((error) => {
console.log(error);
phInstance.exit();
})
我现在头重重地撞在墙上。我应该以某种方式获取网站的脚本并执行它们吗?我是不是错过了指示?
此外,附带说明;如果页面的作用域在第二个".then".
在过去的一周里,我一直在与PhantomJS合作,试图让它用角度渲染的数据来快照页面。我发现最容易做的事情是将page.injectJs('../script.js')
用于任何本地脚本,将page.includeJs('http://jquery.com...')
用于任何外部脚本。由于Phantom是沙盒的,除非您给它JS执行,否则它不会在捕获的页面上执行javascript。这将允许您对使用javascript呈现数据的页面进行屏幕截图。
html底部有一个CData脚本,phantom无法解析。这是项目的传播来源。
<script type="text/javascript">
//<![CDATA[
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadAjaxManager, {"_updatePanels":"","ajaxSettings":[],"clientEvents":{OnRequestStart:"",OnResponseEnd:""},"defaultLoadingPanelID":"","enableAJAX":true,"enableHistory":false,"links":[],"styles":[],"uniqueID":"RadAjaxManager1","updatePanelsRenderMode":0}, null, null, $get("RadAjaxManager1"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadAjaxPanel, {"clientEvents":{OnRequestStart:"",OnResponseEnd:""},"enableAJAX":true,"enableHistory":false,"links":[],"loadingPanelID":"","styles":[],"uniqueID":"ajCheckLoginUser"}, null, null, $get("ajCheckLoginUser"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadAjaxPanel, {"clientEvents":{OnRequestStart:"",OnResponseEnd:""},"enableAJAX":true,"enableHistory":false,"links":[],"loadingPanelID":"","styles":[],"uniqueID":"ajCheckLoginAdmin"}, null, null, $get("ajCheckLoginAdmin"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadAjaxPanel, {"clientEvents":{OnRequestStart:"",OnResponseEnd:""},"enableAJAX":true,"enableHistory":false,"links":[],"loadingPanelID":"","styles":[],"uniqueID":"ajLogoutUser"}, null, null, $get("ajLogoutUser"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadWindow, {"_dockMode":false,"behaviors":0,"clientStateFieldID":"radPortal_ClientState","destroyOnClose":true,"formID":"form1","height":"180px","iconUrl":"","left":"","minimizeIconUrl":"","modal":true,"name":"radPortal","reloadOnShow":true,"showContentDuringLoad":false,"skin":"Office2007","top":"","visibleStatusbar":false,"width":"450px"}, {"close":OnClientClosePortal}, null, $get("radPortal"));
});
Sys.Application.add_init(function() {
$create(Telerik.Web.UI.RadWindowManager, {"behaviors":4,"clientStateFieldID":"windowManagerPortal_ClientState","destroyOnClose":true,"formID":"form1","iconUrl":"","left":"","minimizeIconUrl":"","modal":true,"name":"windowManagerPortal","reloadOnShow":true,"showContentDuringLoad":false,"skin":"Office2007","top":"","visibleStatusbar":false,"windowControls":"['radPortal']"}, null, {"child":"radPortal"}, $get("windowManagerPortal"));
});
//]]>
</script>
一旦您离开与此网站服务器的通信,这些项目也将被销毁。有一些方法可以解决这个问题,但我认为你最好尝试其他方法。我使用npm cheerio加载CDATA html
相关文章:
- 尝试使用Node.js动态路由从IMDB中抓取电影内容.但是在我的output.json文件中没有定义
- 使用htmlunit抓取动态网页
- 使用nodejs和phantomjs进行动态抓取
- 使用 HTML5<输入>字段抓取动态生成的网页
- 如何使用node.js抓取包含动态内容的页面
- 试图在网站上抓取谷歌地图api生成的动态数据,但正常抓取返回空白
- 使用PhantomJS的动态组合下拉框抓取 ASP.NET 站点
- 抓取动态数据
- 原生脚本中的动态抓取?需要抓取页面,能够单击HTML按钮
- jQuery 抓取动态数据 * 属性的值
- 在弹出窗口中分页和网页抓取的CasperJS步骤的动态数量
- 在PhantomJS中动态更改链接,然后单击它来抓取页面
- 使用PhantomJS和pjscrape来抓取动态生成的web内容
- 动态抓取输入/选择值而不直接瞄准- Javascript
- 允许Googlebot抓取动态生成的产品页面
- 抓取动态网页的数据使用scrapy
- 屏幕抓取动态网页在python与Ghost.py
- 使用c#在html文档中动态抓取JavaScript生成的数据
- 反应.js动态抓取对象,导致未定义
- 动态抓取表单ID,关闭父表单中的所有按钮