我想要做的是使用Tag'输入'来获取元素的值。和名称' __ RequestVerificationToken'并使用它,没有页面刷新...如果这是有道理的。
我知道curl,我现在正在做的是从页面获取内容,然后使用DOM获取__RequestVarificationToken的值并在curl POST中使用它。这是我现在的代码,代码不起作用......我怎样才能让它起作用?
<?php
function curl($url, $post=false, $cookie=false){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
if($cookie){
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
}
if($post){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
return curl_exec ($ch);
}
function SendMsg($body,$Subject,$RecipientId){
$dom = new DOMDocument;
$Content = curl("http://m.roblox.com/messages/sendmessage?id=$RecipientId", false, USERNAME);
//print_r($Content);
$dom->loadHTML($Content);
$input = $dom->getElementsByTagName('input');
foreach($input as $node){
print_r($node);
if ($node->nodeName == '__RequestVerificationToken'){
$vartoken = $node->nodeValue;
}
}
curl("http://m.roblox.com/messages/sendmessagework",('__RequestVerificationToken=' .$vartoken . '&RecipientId='.$RecipientId. '&Subject='.$Subject.'&Body='.$body),USERNAME);
echo("Message sent?");
} ?>
&#13;
答案 0 :(得分:1)
如果您指的是名称属性值
<input name="name_here" /> <!-- name attribute -->
然后$node->nodeName
不是你想要的。
改为使用->getAttribute()
:
if($node->getAttribute('name') == '__RequestVerificationToken'){
$vartoken = $node->nodeValue;
}