【发布时间】:2016-11-02 12:19:10
【问题描述】:
我正在尝试抓取网站的完整部分,但问题是我需要的数据从一开始就没有。有没有办法用 PHP 从网站上获取数据?
这是链接:https://www.iamsterdam.com/nl/uit-in-amsterdam/uit/agenda 这是我需要的部分:
在我的帖子被设置为重复后,我尝试了这个 https://stackoverflow.com/a/28506533/7007968 但也不起作用,所以我需要其他解决方案,这就是我尝试过的:
get-website.php
$phantom_script= 'get-website.js';
$response = exec ('phantomjs ' . $phantom_script);
echo $response;
get-website.js
var webPage = require('webpage');
var page = webPage.create();
page.open('https://www.iamsterdam.com/nl/uit-in-amsterdam/uit', function(status) {
console.log(page.content);
phantom.exit();
});
这就是我返回的全部内容(大约 3% 的页面):
</div><div id="ads"></div><script src="https://analytics.twitter.com/i/adsct?p_id=Twitter&p_user_id=0&txn_id=nvk6a&events=%5B%5B%22pageview%22%2Cnull%5D%5D&tw_sale_amount=0&tw_order_quantity=0&tw_iframe_status=0&tpx_cb=twttr.conversion.loadPixels" type="text/javascript"></script></body></html>
所以我觉得我越来越接近这是我经过大量搜索后的结果:
var webPage = require('webpage');
var page = webPage.create();
var settings = {
operation: "POST",
encoding: "utf8",
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify({
DateFilter: 04112016,
LastMinuteTickets: 0,
PageId: "3418a37d-b907-4c80-9d67-9fec68d96568",
Skip: 0,
Take: 12,
ViewMode: 1
})
};
page.open('https://www.iamsterdam.com/api/AgendaApi/', settings, function(status) {
console.log(page.content);
phantom.exit();
});
但我回来的东西看起来不太好:
Message":"An error has occurred.","ExceptionMessage":"Page could not be found","ExceptionType":"System.ApplicationException","StackTrace":" at Axendo.SC.AM.Iamsterdam.Controllers.Api.AgendaApiController.GetResultsInternal(RequestModel requestModel)\r\n at lambda_method(Closure , Object , Object[] )\r\n
等等
希望有人能帮到我,
【问题讨论】:
-
查看我关于页面缺失 97% 的回答。至于为什么 API 不起作用,可能真的是您真的在寻找丢失的页面。如果您想进一步讨论它,您应该在另一个问题中询问 API 问题。
标签: javascript php api phantomjs web-crawler