簡體   English   中英

簡單的 html dom 中的錯誤

[英]Error in simple html dom

當我在 WampServer 中啟動我的代碼時,出現此錯誤:


Warning: file_get_contents(http://www.fragrantica.com/designers/A-Perfume-
Organic.html): failed to open stream: A connection attempt failed because the 
connected party did not properly respond after a period of time, or established 
connection failed because connected host has failed to respond. in 
F:\wamp\www\atr\fragantica\simple_html_dom.php on line 76


我之前測試過一些東西,它適用於我的 3 個 URL,但之后給我
這個錯誤!。我使用我的 wamp 本地服務器和最新版本的 simple_html_dom 版本。我的代碼有點復雜,但可以閱讀!...

 function connect($furl,$fsname){ $fup=fopen("$furl","r"); // open file of urls for read $fname=fopen("$fsname","r"); // open file of file's names for set name $i=0; while(!feof($fup)){ $url=trim(fgets($fup)); // read lines from furl file $name=trim(fgets($fname)); $fdoc=fopen("$name.txt","w"); // make a new file for put contents in it $html=file_get_html("$url"); // read contents from favurites html page foreach($html->find("div.perfumeslist p") as $tag){ foreach($tag->find("a") as $alink){ $perlink="http://www.fragrantica.com".$alink->href; fwrite($fdoc,"##PERFUME_LINK:##".$perlink."\\n"."\\n"); } foreach($tag->find("img") as $im){ fwrite($fdoc,"##THUMB_SRC:##".$im->src."\\n"); } foreach($tag->find("span.mtext") as $sp){ fwrite($fdoc,"##SEX:##".$sp->innertext."\\n"); } $perfume=file_get_html("$perlink"); foreach($perfume->find("div") as $disc){ if(strcmp($disc->itemprop,"description")===0){ fwrite($fdoc,"##DESCRIPTION:##".$disc->innertext."\\n"); } } foreach($perfume->find("div#mainpicbox img") as $per){ $pic=$per->src; fwrite($fdoc,"##MAINPICURL:##".$pic."\\n"); } foreach($html->find("div") as $tag){ if(strcmp($tag->style,"width: 230px; float: left; text-align: center; clear: left;")===0){ foreach($tag->find("p") as $notes){ fwrite($fdoc,"##NOTES:##".$notes->innertext."\\n"."\\n"); } } } fwrite($fdoc,"___________________________________________________________________"."\\n"); } fclose($fdoc); } fclose($fup); fclose($fname); }

關於我的代碼:
在這個函數中,我讀取了兩個文件:一個是我的文本文件的名稱,另一個是
對於 URL 文件。首先從這些文件中逐行讀取,直到
到文件末尾然后使用 file_get_html 並獲取標簽和屬性
獲取它的鏈接源和內部文本...

$ch = curl_init();
$timeout = 20;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$fileContents = curl_exec($ch);
curl_close($ch);

// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($fileContents);

試試這個,我沒有執行這個所以我不確定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM