当我从 WAMP 上的 cmd.exe [命令行] 运行此脚本时,我得到:
Could not retrieve data from OpenAmplify.file_get_contents(http://portal
tnx.openamplify.com/AmplifyWeb/AmplifyThis?apiKey=MY_API_KEY_GOES_HERE): failed to open stream: HTTP request failed! (C:\wamp\www\Learning_Query_Pa
th\src\QueryPath\QueryPath.php: 4053)
当我通过 Firefox 浏览器 [v 19.0] 从 localhost 运行此脚本时,我得到:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\Learning_Query_Path\src\QueryPath\QueryPath.php on line 4525
这是我使用的脚本:
<?php
require 'src/QueryPath/QueryPath.php';
$url = 'http://portaltnx.openamplify.com/AmplifyWeb/AmplifyThis?';
$key = 'I_PUT_MY_API_KEY_HERE';
$text = 'I_PUT_TEXT_HERE';
$params = array(
'apiKey' => $key,
);
$url .= http_build_query($params);
$options = array(
'http' => array(
'method' => 'POST',
'user_agent' => 'QueryPath/2.0',
'header' => 'Content-type: application/x-www-form-url-encoded',
'content' => http_build_query(array('inputText' => $text)),
),
);
$context = stream_context_create($options);
try {
$qp = qp($url, NULL, array('context' => $context));
}
catch (Exception $e) {
print "Could not retrieve data from OpenAmplify." . $e->getMessage();
exit;
}
$qp->find('ProperNouns>TopicResult>Topic>Name')->slice(0, 20);
$out = qp(QueryPath::HTML_STUB, 'body')->append('<ul/>')->find('ul');
foreach ($qp as $name) {
$out->append('<li>' . $name->text() . '</li>');
}
$out->writeHTML();
?>
我怎样才能使这项工作?
PS Open Amplify 是一个 Web 服务,它获取提供的文本并在对其进行分析后,返回许多关于它的有趣内容。我真的很想完成这项工作并且是 QueryPath 的忠实粉丝,所以我只对如何使它与 QueryPath 一起工作的建议感兴趣!