我想从Web文档中提取两个值。值为api_key和authenticity_token。我已经写了一个函数,但问题是它只是拉出api_key。有人能帮助我与另一片这个功能,这将使我拉出authenticity_token,感谢:PHP DOMDocument:当一个值没有ID值时,如何从网页中提取两个(2)值
这是我为我的功能代码:
<?php
class apiKey{
public $apikey;
public $authenticity_token;
function getApiKey(){
//Get api_key and pass it in
$apikey = null;
$doc = new DOMDocument();
$semcatStartUrl = 'https://entryform.semcat.net/1800stonewall';
libxml_use_internal_errors(true);
$doc->loadHTMLFile("$semcatStartUrl");
libxml_clear_errors();
$apikey = $doc->getElementById('api_key')->getAttribute('value');
return $apikey;
}
function getAuthenticityToken(){
//My guesstimate this doesn’t work because the form hasn’t been/ //submitted yet
$authenticity_token = $_POST['authenticity_token'];
return $authenticity_token;
}
}
?>
任何帮助将不胜感激。再次感谢!
做了一些细微的改动我会在回答中发布整个工作代码。感谢你的帮助,使我朝着正确的方向前进。 – LOwens1931 2014-09-30 17:10:04