2012-05-11 55 views
2

我的目標網站包含這樣獲取元素通過ID或用戶名在捲曲

<form> 
<input type="text" name="suggest" value="www.google.com"> 
<input type="submit" value="submit"> 
</form> 

代碼我用捲曲的PHP得到這個頁面

<?php 
$url="http://mysite.com"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
$result = curl_exec ($ch); 
echo $result; 
curl_close($ch); 
?> 

如何使用ID或名字,我得到一個元素值?例如輸入名稱中的「www.google.com」=「建議」。感謝您的幫助。

我不能使用此代碼進行遠程是這樣的:

<?php 
require 'Path/QueryPath.php'; 
qp('http://hipfile.com/bbgfom5ej9tm/zakhme_shaneie_haava_dvdrip.wmv.html/')- 

find('[password="login"]')->writeHTML(); ?>

,並返回該錯誤

Fatal error: Uncaught exception 'QueryPathParseException' with message 'DOMDocument::load() [domdocument.load]: AttValue: " or ' expected in http://hipfile.com/bbgfom5ej9tm/zakhme_shaneie_haava_dvdrip.wmv.html/ , line: 18 (C:\xampplite\htdocs\test1\Path\QueryPath.php: 2106)' in C:\xampplite\htdocs\test1\Path\QueryPath.php:2346 Stack trace: #0 [internal function]: QueryPathParseException::initializeFromError(2, 'DOMDocument::lo...', 'C:\xampplite\ht...', 2106, Array) #1 C:\xampplite\htdocs\test1\Path\QueryPath.php(2106): DOMDocument->load('http://hipfile....', 0) #2 C:\xampplite\htdocs\test1\Path\QueryPath.php(179): QueryPath->parseXMLFile('http://hipfile....', NULL, NULL) #3 C:\xampplite\htdocs\test1\Path\QueryPath.php(23): QueryPath->__construct('http://hipfile....', NULL, Array) #4 C:\xampplite\htdocs\test1\index.php(3): qp('http://hipfile....') #5 {main} thrown in C:\xampplite\htdocs\test1\Path\QueryPath.php on line 2346

能幫我嗎?我使用了兩個DOM和simplehtmldom,但沒有爲我工作。它僅適用於本地頁面。

+0

這可能是有用的:http://simplehtmldom.sourceforge.net/ –

+0

的QueryPath是新simplehtmldom –

回答

3

您將不得不使用DOM解析器。最近我一直在使用查詢路徑:http://querypath.org/

qp($result)->find('[name="name"]'); 
+0

嘗試和回報錯誤=致命錯誤:帶有消息'DOMDocument :: loadHTMLFile()'的未捕獲異常'QueryPathParseException' –

1

試試這個

<?php 

$url="http://mysite.com"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
$result = curl_exec ($ch); 
echo $result; 
curl_close($ch); 

// include simple_html_dom class here 
// which can be downloaded from http://simplehtmldom.sourceforge.net/ 

$oDom = new simple_html_dom(); 
$oDom->load($result); 
$textFieldValue = $oDom->find('[name="suggest"]',0)->value; 
echo $textFieldValue; // will return www.google.com 

?> 
+0

致命錯誤:在第40行C:\ xampplite \ htdocs \ test1 \ index.php中找不到類'simple_html_dom'我如何找到此類? –

+0

請訪問http://simplehtmldom.sourceforge.net/並下載可在「下載和文檔」下找到的類。將其包含在腳本 – Sanjay

+0

謝謝。但我不能包括我包括哪部分?下載包,但我不知道 –