2012-02-01 140 views
0

這是我的代碼來抓取所有的pdf鏈接,但它不起作用。如何從這些鏈接下載並保存到我的電腦上的文件夾?如何從html鏈接抓取並下載所有pdf文件?

<?php 
set_time_limit(0); 
include 'simple_html_dom.php'; 

$url = 'http://example.com'; 
$html = file_get_html($url) or die ('invalid url'); 

//extrack pdf links 
foreach($html->find('a[href=[^"]*\.pdf]') as $element) 
echo $element->href.'<br>'; 
?> 
+0

它看起來像你有一個錯字,在foreach循環中,$ htnl應該是$ html。如果這不在你的原始代碼中,你得到的錯誤究竟是什麼? – ggreiner 2012-02-01 22:05:48

+2

「does not work」>。< – 2012-02-01 22:12:15

+0

@ggreiner在我的ori代碼中,沒有錯別字,對不起。我錯過了這裏的錯字。空白結果在我的網頁 – puresmile 2012-02-01 22:54:06

回答

2
foreach($htnl->find('a[href=[^"]*\.pdf]') as element) 
      ^---typo. should be an 'm'  ^---typo. need a $ here 

請問你的代碼不是因爲上面的錯字的「不行」,其他?

+0

ups,對不起,在我的原始代碼中,沒有錯字 - .-。它不起作用,空白結果在我的網頁 – puresmile 2012-02-01 22:52:41