2014-12-06 29 views
1

我想要做的是获取具有标记'input'和名称'__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){ 
 
\t $dom = new DOMDocument; 
 
\t $Content = curl("http://m.roblox.com/messages/sendmessage?id=$RecipientId", false, USERNAME); 
 
\t //print_r($Content); 
 
\t $dom->loadHTML($Content); 
 
\t $input = $dom->getElementsByTagName('input'); 
 
\t foreach($input as $node){ 
 
\t \t print_r($node); 
 
\t \t if ($node->nodeName == '__RequestVerificationToken'){ 
 
\t \t \t $vartoken = $node->nodeValue; 
 
\t \t } 
 
\t } 
 
\t curl("http://m.roblox.com/messages/sendmessagework",('__RequestVerificationToken=' .$vartoken . '&RecipientId='.$RecipientId. '&Subject='.$Subject.'&Body='.$body),USERNAME); 
 
\t echo("Message sent?"); 
 
} ?>
任何帮助,将不胜感激!谢谢。

回答

1

如果你指的是name属性值

<input name="name_here" /> <!-- name attribute --> 

然后$node->nodeName是不是你在找什么。

使用->getAttribute()代替:

if($node->getAttribute('name') == '__RequestVerificationToken'){ 
    $vartoken = $node->nodeValue; 
} 
+0

哇,原来与此修复程序,它的工作原理吧!谢谢! :) – POC0bob 2014-12-06 05:49:42

+0

@ POC0bob确定男人很高兴这有帮助 – Ghost 2014-12-06 05:50:22