2014-12-06 57 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