通过phantomjs获取URL片段

问题描述

我需要获取当前URL的URL片段并将片段(哈希)放入php变量。像这样:

//creating array of report struct
var currentReport = [report]()
//currentReport.append(report(question:questions,AnswersChosen:[String](),userCount:0))
        
//array for what users are selecting
answerChosen.append(sender.title(for: .normal)!)
//print (answerChosen)
//currentReport.AnswersChosen = answerChosen
print(answerChosen)
        
//counting number of times wrong button is pressed
ActionCount += 1
//currentReport.userCount = ActionCount
print(ActionCount)
currentReport.append(report(question:questions[currentQuestion],AnswersChosen:answerChosen,userCount:ActionCount))
print(currentReport)

当我在$current_url = exec(phantomjs script.js); 文件中使用window.location.href时,它显示script.js url。 我需要获取php文件的当前URL,而该文件是fragment(hash)。

我该怎么做。请帮忙。

更新: 我需要获取像phantomjs这样执行的当前php文件的URL:examle.com/need_url_of_this_page.php#11111

解决方法

不确定您要问的是什么,但我想这是您的script.js中的问题:

var webPage = require('webpage');
var page = webPage.create();

page.open('http://phantomjs.org',function (status) {
  var url = page.url;
  console.log('URL: ' + url);
  phantom.exit();
});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...